我不确定我是否正确理解了您的问题,在这里我分享一种方法,longPressRecognizer
只要用户按下该视图,该方法就会监听该视图并为其设置动画。当用户停止按下时,视图动画回到其默认状态。您可以通过将位置检查语句添加到 if/else if 来检查用户手势是否满足您的位置条件。希望有帮助。
- (void)longPressed:(UILongPressGestureRecognizer *)recognizer {
UIView *longPressView = self.longPressView;
if (recognizer.state == UIGestureRecognizerStateBegan) {
[UIView animateWithDuration:longPressDuration
delay:0.f
options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionBeginFromCurrentState
animations:^{
//do stuff
}
completion:^(BOOL finished) {
if (finished) {
//long press exceeded time limit: do stuff
}
}];
}
else if (recognizer.state == UIGestureRecognizerStateEnded) {
[UIView animateWithDuration:longPressDuration/2.0
delay:0.f
options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionBeginFromCurrentState
animations:^{
//do stuff
}
completion:nil];
}
}