我有一个 UIView 长按时会翻转。在模拟器中效果很好,但在现实世界中,人的手指在按下时会有微小的动作。这些微小的动作重置手势并立即触发手势结束状态。
- (void)viewDidLoad {
...
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(didLongPress:)];
longPress.minimumPressDuration = 0.7;
[self.view addGestureRecognizer:longPress];
}
- (void)didLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
if ( gestureRecognizer.state == UIGestureRecognizerStateBegan )
{
[UIView transitionFromView:self.questionCardView toView:self.answerCardView
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:nil];
}
else
{
[UIView transitionFromView:self.answerCardView toView:self.questionCardView
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished){
[self.view addSubview:self.questionCardView];
[self.view sendSubviewToBack:self.questionCardView];
}];
}
}