ios开发:UINavigationController反方向滑动push

时间:2014-05-26 05:33:19   收藏:0   阅读:381

新建个UINavigationController的类别:


#import "UINavigationController+CustomAnimation.h"


@implementation UINavigationController (CustomAnimation)


- (void)customPushViewController:(UIViewController *)viewController

{

    viewController.view.frame = (CGRect){-viewController.view.frame.size.width, 0, viewController.view.frame.size};

    [self.topViewController.view addSubview:viewController.view];

    [UIView animateWithDuration:.35f

                     animations:^{

                         viewController.view.frame = (CGRect){0, 0, self.view.bounds.size};

                     }];

}

@end


这种方法是将新的View 加到了self.navigationController.topViewController 上,然后加上了滑动动画。

使用

- (void)backToHome

{

    [UIView beginAnimations:@"popView" context:NULL];

    [UIView setAnimationDelegate:self];

    [UIView setAnimationDuration:.5f];

    [UIView setAnimationDidStopSelector:@selector(popAnimationDidStop)];

    self.view.frame = CGRectMake(-CGRectGetWidth(self.view.frame), 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));

    [UIView commitAnimations];

}

可以作为pop的动画使用

ios开发:UINavigationController反方向滑动push,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!