今天做一个需求:从顶部弹出一个视图,一段延时后该视图自动消失或者点击该视图使其消失。
于是打算从顶部弹出一个button,便这样写:
[UIView animateWithDuration:0.3 animations:^{
btn.frame=CGRectMake(0, IS_HOTSPOT_CONNECTED?40:0, SIZE.width, floatH);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 delay:8 options:UIViewAnimationOptionCurveEaseInOut animations:^{
btn.frame=CGRectMake(0, -floatH, SIZE.width, floatH);
} completion:^(BOOL finished) {
[btn removeFromSuperview];
}];
}];
发现UIView Animation动画的delay会阻塞btn的点击事件,就是说视图在显示的8秒内是无法点击的。无奈只能更换方法:
[UIView animateWithDuration:0.3 animations:^{
btn.frame=CGRectMake(0, IS_HOTSPOT_CONNECTED?40:0, SIZE.width, floatH);
} completion:^(BOOL finished) {
[self performSelector:@selector(btnPushClick:) withObject:view afterDelay:8];
}];
-(void)btnPushClick:(UIButton *)sender
{
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
sender.frame=CGRectMake(0, -sender.frame.size.height, SIZE.width, sender.frame.size.height);
} completion:^(BOOL finished) {
[sender removeFromSuperview];
}];
}