//侧滑手势
- (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];