ios8中 利用UIPresentationController 自定义转场

来源:互联网 发布:mac粉底液色号分类 编辑:程序博客网 时间:2024/06/04 18:54

1、UIPresentationController 介绍

UIPresentationController 是 iOS8 新增的一个 API,用来控制 controller 之间的跳转特效。比如希望实现一个特效,显示一个窗口,大小和位置都是自定义的,并且遮罩在原来的页面上。在之前,可以操作view的一些方法来实现。

2、使用介绍

1. 设置目标控制器的 转场代理 和 展示方法

controller.modalPresentationStyle = UIModalPresentationStyle.Custom// 设置 动画样式controller.transitioningDelegate = transtinoDelegate// 此对象要实现 UIViewControllerTransitioningDelegate 协议

2. transtionDelegate 实现 UIViewControllerTransitioningDelegate 协议方法

// 返回控制控制器弹出动画的对象optional func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning?// 返回控制控制器消失动画的对象optional func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?@availability(iOS, introduced=8.0)// 返回控制控制器跳转的对象optional func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController?

3. 控制控制器跳转的类

控制控制器跳转的类继承自 UIPresentationController 

/*构造方法:参数:presentedViewController将要跳转到的目标控制器presentingViewController跳转前的原控制器*/init(presentedViewController: UIViewController!, presentingViewController: UIViewController!)

常用的属性和方法
presentedViewController:要 modal 显示的视图控制器presentingViewController:低层的视图控制器containerView()容器视图presentedView()被展现的视图func presentationTransitionWillBegin()跳转将要开始func presentationTransitionDidEnd(completed: Bool)跳转完成func dismissalTransitionWillBegin()dismiss 将要开始func dismissalTransitionDidEnd(completed: Bool)dismiss 完成func frameOfPresentedViewInContainerView()目标 控制器设置

4. 控制动画类

控制动画对类继承自 UIViewControllerAnimatedTransitioning

// 执行动画的时间func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval// 动画过程设置func animateTransition(transitionContext: UIViewControllerContextTransitioning)

5. 总结

1. 设置目标控制器的转场代理

2. 专场代理返回三个对象用于控制转场过程

3. 控制控制器转场对象,可以在此做专场前后的操作,例如添加遮罩等

4. 控制转场动画,用于设置目标控制器出现或消失的动画,以及控制器的大小样式等。

3. API 详细介绍

1、UIViewControllerTransitioningDelegate

protocol UIViewControllerTransitioningDelegate : NSObjectProtocol {// 返回控制控制器消失动画的对象optional func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning?// 返回控制控制器跳转的对象optional func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?optional func interactionControllerForPresentation(animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning?optional func interactionControllerForDismissal(animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning?@availability(iOS, introduced=8.0)// 返回控制控制器弹出动画的对象optional func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController?}

2、UIPresentationController




4.自定义跳转 Demo

稍后。。。


1 1
原创粉丝点击