iOS7 Custom ViewController Transitions


@interfaceBouncePresentAnimationController :NSObject

- (NSTimeInterval)transitionDuration:

(id)transitionContext {

return2.0;

}

- (void)animateTransition:

(id)transitionContext {

1.获取toViewController ,通过transitionContextviewControllerForKey:UITransitionContextToViewControllerKey

2.获取当animation 完成时,你展示下一个viewController显示的frame (可以自己定义frame,也可以通过参数finalFrameForViewController(方法):toViewController,获取toViewController的frame)

3. obtain the container view

UIView*containerView = [transitionContextcontainerView];

4. 设置toViewController.view初始的位置 (把它的的位置放在屏幕下面,)

5.[containerViewaddSubview:toViewController.view];

6. 获取动画时间,通过第一个协议方法

NSTimeIntervalduration =[selftransitionDuration:transitionContext];

7.[UIViewanimateWithDuration:duration

animations:^{ toViewController.view.frame= finalFrame; }completion:^(BOOLfinished) {

[transitionContextcompleteTransition:YES];//inform the context of completion ,removes the from- view from the container

}];

}

外面的ViewController调用上面的这个自定义的转场,

1.让外面的ViewController遵循UIViewControllerTransitioningDelegate这个协议

2.#import"BouncePresentAnimationController.h"

3.@implementationMasterViewController {

BouncePresentAnimationController*_bounceAnimationController;

}

4.初始化

- (id)initWithCoder:(NSCoder*)aDecoder {

if(self= [superinitWithCoder:aDecoder]) {

_bounceAnimationController= [BouncePresentAnimationControllernew];

}

return self; }

5.实现delegate

- (id) animationControllerForPresentedController:

(UIViewController*)presented presentingController:

(UIViewController*)presenting sourceController: (UIViewController*)source {

return_bounceAnimationController;

}

6.转场调用

UIViewController*toVC = [UIViewController alloc]init];

toVC.transitioningDelegate=self;

self.navigation pushViewController - - - -];

推荐阅读更多精彩内容