iOS交互式动画转场
程序员文章站
2022-03-25 08:52:43
...
iOS交互式动画转场
实现UIPercentDrivenInteractiveTransition
-(void)updateInteractiveTransition:(CGFloat)percentComplete 更新百分比,一般通过手势识别的长度之类的来计算一个值,然后进行更新。
-(void)cancelInteractiveTransition 取消操作,返回切换前的状态
–(void)finishInteractiveTransition 完成操作,更新到切换后的状态
当手势结束,根据手势的状态判断是取消还是完成,调用如下方法
finishInteractiveTransition 或者 cancelInteractiveTransition 方法.
- (void)handlePopRecognizer:(UIScreenEdgePanGestureRecognizer*)recognizer {
// 计算滑了多远
CGFloat progress = [recognizer translationInView:self.view].x / (self.view.bounds.size.width * 1.0);
progress = MIN(1.0, MAX(0.0, progress));
if (recognizer.state == UIGestureRecognizerStateBegan) {
// 创建过渡对象,弹出viewController
self.interactivePopTransition = [[UIPercentDrivenInteractiveTransition alloc] init];
[self.navigationController popViewControllerAnimated:YES];
}
else if (recognizer.state == UIGestureRecognizerStateChanged) {
// 更新 interactive transition 的进度
[self.interactivePopTransition updateInteractiveTransition:progress];
}
else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled) {
// 完成或者取消过渡
if (progress > 0.5) {
[self.interactivePopTransition finishInteractiveTransition];
}
else {
[self.interactivePopTransition cancelInteractiveTransition];
}
self.interactivePopTransition = nil;
}
}
上一篇: Matlab画GIF图像并保存