模态控制器的侧滑返回

//侧滑手势
- (void)addEdgePan {
    UIScreenEdgePanGestureRecognizer *edgePan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(edgePanAction:)];
    edgePan.edges = UIRectEdgeLeft;
    [self.view addGestureRecognizer:edgePan];
}

- (void)edgePanAction:(UIScreenEdgePanGestureRecognizer *)edgePan {
    CGPoint point = [edgePan translationInView:self.view];
    if (edgePan.state == UIGestureRecognizerStateBegan) {
        self.navigationController.view.transform = CGAffineTransformMakeTranslation(point.x, 0);
    } else if (edgePan.state == UIGestureRecognizerStateChanged) {
        self.navigationController.view.transform = CGAffineTransformMakeTranslation(point.x >= 0 ? point.x : 0, 0);
    } else {
        if (point.x > 50) {
            [UIView animateWithDuration:.35 animations:^{
                self.navigationController.view.transform = CGAffineTransformMakeTranslation(self.view.frame.size.width, 0);
            } completion:^(BOOL finished) {
                [self.navigationController dismissViewControllerAnimated:NO completion:nil];
            }];
        } else {
            [UIView animateWithDuration:.35 animations:^{
                self.navigationController.view.transform = CGAffineTransformMakeTranslation(0, 0);
            }];
        }
    }
}
//模态进入
UIViewController *vc = [UIViewController new];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
       
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;//UIModalTransitionStyleCrossDissolve;

//这个属性 让原控制器保持不消失,不走viewDidDisappear. 避免侧滑黑屏
nav.modalPresentationStyle = UIModalPresentationCustom;

[self presentViewController:nav animated:YES completion:nil];

更多

仿 push进入, 退出 动画

CATransition *animation = [CATransition animation];
animation.duration = 0.4;
//[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//UIViewAnimationCurveEaseInOut
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromRight;
[parent.view.window.layer addAnimation:animation forKey:nil];
[parent presentViewController:nav animated:NO completion:nil];
CATransition *animation = [CATransition animation];
animation.duration = 0.35;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromLeft;
[self.view.window.layer addAnimation:animation forKey:nil];
[super dismissViewControllerAnimated:NO completion:nil];
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容