UIPresentationController~

iOS8中UIViewController中新增presentationController属性,

@property (nonatomic,readonly) UIPresentationController *presentationController NS_AVAILABLE_IOS(8_0);

当我们需要modal一个控制器的时候,例如A->B,我们可以自定义B控制器modal的样式,也可以使用系统提供的modal样式

如果要系统的modal样式,只需要设置B控制器的modalPresentationStyle就可以了.如果要自定义modal样式,则需要设置B控制器的modalPresentationStyle为UIModalPresentationCustom;

这样系统就知道,modal出B控制器的时候要使用自定义的modal样式

modal出B控制器的样式是通过B控制器询问自身的属性--transitioningDelegate得到的

@property (nonatomic,assign) id <UIViewControllerTransitioningDelegate> transitioningDelegate NS_AVAILABLE_IOS(7_0);

可以看到transitioningDelegate只是一个遵守<UIViewControllerTransitioningDelegate>协议的对象

首先B控制器会调用delegate下面这个方法,询问transitioningDelegate应该用哪一个PresentationController来控制modal

- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source NS_AVAILABLE_IOS(8_0);

然后B控制器会询问transitioningDelegate,自己modal出来和dismiss消失的时候要以怎样的方式(自己写动画)进行

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source;

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed;

从代码可以看出,控制modal和dismiss动画的是一个遵守UIViewControllerAnimatedTransitioning协议的对象

这个协议很简单,第一个是modal或者dismiss完成的时间,第二个是B控控制器modal或者dismiss时通知delegate的方法,动画要写在这里面,通过transitionContext取出相应的View,添加动画,第三个方法会在[transitionContext  completeTransition:]调用后被系统调用

// This is used for percent driven interactive transitions, as well as for container controllers that have companion animations that might need to
// synchronize with the main animation.
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext;
// This method can only  be a nop if the transition is interactive and not a percentDriven interactive transition.
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext;

@optional

// This is a convenience and if implemented will be invoked by the system when the transition context‘s completeTransition: method is invoked.
- (void)animationEnded:(BOOL) transitionCompleted;

如果要添加一个自定义的CView,将CView添加到A.view上,将B.view添加到CView上,以这种方式展Modal出B的时候,可以将CView写在UIPresentationController里面,

如果还要给CView添加动画的话,可以用transitionCoordinator来执行动画

id<UIViewControllerTransitionCoordinator> transitionCoordinator = self.presentingViewController.transitionCoordinator;

下面附上demo一个~~~~https://github.com/yang7/zxyPresentationController

时间: 2024-08-25 10:59:49

UIPresentationController~的相关文章

iOS:自定义模态动画 --UIPresentationController

UIPresentationController :展示控制器,是iOS8的一个新特性,用来展示模态窗口的.它是所有模态控制器的管理者. 即: 1> 管理所有Modal出来的控制器 2> 管理所有通过- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion方法显示出来的控制器 3> 

ios8中 利用UIPresentationController 自定义转场

1.UIPresentationController 介绍 UIPresentationController 是 iOS8 新增的一个 API,用来控制 controller 之间的跳转特效.比如希望实现一个特效,显示一个窗口,大小和位置都是自定义的,并且遮罩在原来的页面上.在之前,可以操作view的一些方法来实现. 2.使用介绍 1. 设置目标控制器的 转场代理 和 展示方法 controller.modalPresentationStyle = UIModalPresentationStyl

iOS iOS8新特性--UIPresentationController

1. UIPresentationController的作用 1>管理所有Modal出来的控制器 2>管理通过这个方法  - (void) presentViewController:(UIViewController *) animated:(BOOL) completion:^(void)completion;显示出来的控制器 3>管理\监听 切换控制器的过程 2. UIPresentationController的作用 1>控制器一旦调了present方法,控制器的prese

iOS 利用UIPresentationController自定义转场动画

1. 系统默认modal出来的动画效果默认是从屏幕底部爬出来的 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ secondVC *second = [[secondVC alloc] init];  [self presentViewController:second animated:YES completion:nil]; } 2. 想自定义转场动画,首先设置 展示样式 和 过渡代理 secondVC *s

iOS8新特性 UIPresentationController(一)

UIPresentationController(一) popover.alert.action sheet与search的新特性 刘冰发表于测试?看我的 刘冰 2014年07月02日 发表 收录了本文的主题 测试?看我的 一枚测试人员很小,这个世界很大,让我们的分享无限!学点有用的:) + 订阅更多收录本文的主题 UIPresentationController是提供高级视图切换的类.它让管理present ViewController的过程变得简单. 先讲一些presentation基础知识

iOS8特性 UIPresentationController

UIPresentationController是提供高级视图切换的类.它让管理present ViewController的过程变得简单. 先讲一些presentation基础知识,在iPad的设置页面,可以通过popOver弹出一个UIViewController,这个弹出的,可以和用户交互的Controller叫做PresentedViewController,而后面那个被部分遮挡的UIViewController叫做PresentingViewController,而在UIPresent

UIPresentationController 教程:入门

原文:UIPresentationController Tutorial: Getting Started 作者:Ron Kliffer 译者:kmyhy 很久以来,View Controller Presentation 就已经是每个 iOS 开发者工具中不可或缺的部分.你之前肯定用过 present(_:animated:completion:) ,但如果你和许多开发者一样,很可能你仍然只会使用 iOS 内置的转换样式.在这篇教程中,你将学到如何用自定义的转换动画和自定义呈现样式显示 Vie

iOS8的UIPresentationController

本文转载至 http://kyfxbl.iteye.com/blog/2147888 从iOS8开始,controller之间的跳转特效,需要用新的API UIPresentationController来实现.比如希望实现这样一个特效:显示一个模态窗口,大小和位置是自定义的,遮罩在原来的页面上.在iOS8之前,可以在viewWillAppear里设置superview的frame: Objc代码   - (void)presentModal:(NSDictionary*)result { YL

Displaying Your Views at Runtime

UIKit automatically loads views from your storyboard file when they are needed. As part of the loading process, UIKit performs the following sequence of tasks: Instantiates views using the information in your storyboard file. Connects all outlets and