视图执行缩放动画时Pan Gesture无法识别的原因探究
问题原因及解决方案
原因
UIView默认动画会自动禁用视图的用户交互,包括你给currentView添加的Pan手势识别器。因为系统默认的动画选项里不包含UIViewAnimationOptionAllowUserInteraction,所以在动画执行的0.3秒内,currentView无法响应任何触摸事件,自然识别不了Pan手势,必须等动画结束后才能恢复交互。
修复方法
修改动画的options参数,添加上UIViewAnimationOptionAllowUserInteraction,让动画期间视图依然能响应手势:
[self.currentView addGestureRecognizer:self.pangr]; // added somewhere above in the code [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction animations:^{ self.currentView2.transform = CGAffineTransformMakeTranslation(0, self.currentView2.frame.size.height); self.currentView.transform = CGAffineTransformMakeScale(1.0, 1.0); } completion:^(BOOL finished) { self.currentView2 = nil; }];
注:如果动画涉及视图的位置、尺寸变换,手势识别的响应区域会跟随视图的实时状态自动调整,无需额外处理。
内容的提问来源于stack exchange,提问作者DST
相关产品推荐
相关产品推荐

