关于UIView动画

今天做一个需求:从顶部弹出一个视图,一段延时后该视图自动消失或者点击该视图使其消失。
于是打算从顶部弹出一个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];
    }];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容