[英]iOS adding an animation with Pan Gesture Recognizer
我正在尝试在平移手势识别器中制作动画。 但是,当识别器到达屏幕上我想要的位置时,将调用UIStateGestureRecognizerStateEnded,并且动画无法正确触发。 这就是我要这样做的方式。 我该如何做才能使我的动画流畅且不会破坏手势识别器的状态。
-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer
{
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x, recognizer.view.center.y + translation.y);
self.lineView1.center = CGPointMake(self.lineView1.center.x, recognizer.view.center.y + translation.y - 337.5f);
self.lineView2.center = CGPointMake(self.lineView2.center.x, recognizer.view.center.y +translation.y + 337.5f);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
//THIS CODE IS NOT ALLOWING THE ANIMATION TO RUN SMOOTHLY? AND ENDS THE GESTURE'S STATE.
if ((recognizer.view.center.y + translation.y)>300 && (recognizer.view.center.y + translation.y)<345) {
[UIView animateWithDuration:3.5 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
self.joinHorzConst.constant= 60;
self.joinLabel.alpha = 1;
} completion:^(BOOL finished) {
//completion
}];
}
if (recognizer.state == UIGestureRecognizerStateEnded) {
[UIView animateWithDuration:.35 delay:0 options:UIViewAnimationOptionCurveEaseInOut
animations:^{
recognizer.view.center = CGPointMake(recognizer.view.center.x, 121.5f);
self.lineView1.center = CGPointMake(281, -216);
self.lineView2.center = CGPointMake(281, 459);
} completion:^(BOOL finished) {
[UIView animateWithDuration:.2 animations:^{
recognizer.view.center = CGPointMake(recognizer.view.center.x, 147.5f);
self.lineView1.center = CGPointMake(281, -189);
self.lineView2.center = CGPointMake(281, 486); } completion:^(BOOL finished) {
[UIView animateWithDuration:.1 animations:^{
recognizer.view.center = CGPointMake(recognizer.view.center.x, 141.5f);
self.lineView1.center = CGPointMake(281, -196);
self.lineView2.center = CGPointMake(281, 479);
}];
}];
}];
}
}
提前致谢!
编辑:正是我希望我的动画如何工作:
用户可以像沿滑块一样在y轴上上下拖动识别器。 当滑块按钮到达某些y轴(300-345)之内时,我希望在我的一个标签上放一个动画,将其向左稍微推一下,然后将alpha调高。
现在如何运作:
现在,滑块可以正常工作,直到我到达y轴(介于300-345之间)时,此时我的gestureReconizerStatedidEnd会被调用,并且滑块会以所需的动画返回到其原始位置。 我不希望这种情况发生。 我希望滑块继续自由移动,但是标签动画会发生,就像滑块在300-345尺寸范围内一样。
我设置带有约束的标签x值的方式似乎在打乱手势? 不确定。 但是,这就是现在的工作方式。
if ((recognizer.view.center.y + translation.y)>300 && (recognizer.view.center.y + translation.y)<345) {
[UIView animateWithDuration:.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
[self.joinLabel setCenter:CGPointMake(183, 324)];
self.joinLabel.alpha = 1;
} completion:^(BOOL finished) {
//completion
}];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.