日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > iOS7使用代理自定義導航轉場動畫

iOS7使用代理自定義導航轉場動畫

來源:程序員人生   發布時間:2014-10-10 08:00:01 閱讀次數:3303次

如果你已經厭倦了使用UINavigationController進行簡單粗暴的push和pop轉場操作,你完全可以使用自定義的導航轉場效果,iOS7提供了許多漂亮的代理方法幫助你實現各種自定義動畫,下面演示一個簡單的導航轉場動畫Demo的實現過程,效果如圖一所示:




STEP 1: 創建一個項目,其中包含,一個名為FirstViewController和一個SecondViewController的視圖控制器,兩個繼承自NSObject的PopAnimation和PushAnimation類。


STEP2:使用UIViewControllerAnimatiedTransitioning代理方法自定義Push 動畫

 1.)讓PopAnimation使用UIViewControllerAnimatedTransitioning代理的方法:

@interface PushAnimation : NSObject <UIViewControllerAnimatedTransitioning>
2.)PopAnimation的實現


- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext { UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; [[transitionContext containerView] addSubview:toViewController.view]; toViewController.view.alpha = 0; [UIView animateWithDuration:0.3*[self transitionDuration:transitionContext] animations:^{ fromViewController.view.transform = CGAffineTransformMakeScale(0.6, 0.6); toViewController.view.alpha = 0.3; } completion:^(BOOL finished) { [UIView animateWithDuration:0.3*[self transitionDuration:transitionContext] animations:^{ fromViewController.view.transform = CGAffineTransformMakeScale(1.1, 1.1); toViewController.view.alpha = 0.6; } completion:^(BOOL finished){ [UIView animateWithDuration:0.4*[self transitionDuration:transitionContext] animations:^{ fromViewController.view.transform = CGAffineTransformMakeScale(0.1, 0.1); toViewController.view.alpha = 1.0; } completion:^(BOOL finished){ fromViewController.view.transform = CGAffineTransformIdentity; [transitionContext completeTransition:![transitionContext transitionWasCancelled]]; }]; }]; }]; }

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext { return 3.0f; }

STEP 3: 使用UIViewControllerAnimatiedTransitioning代理方法自定義Pop 動畫

@interface PopAnimation : NSObject <UIViewControllerAnimatedTransitioning>

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext { UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; [[transitionContext containerView] addSubview:toViewController.view]; toViewController.view.alpha = 0; toViewController.view.transform = CGAffineTransformMakeScale(0.1, 0.1); [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ toViewController.view.transform = CGAffineTransformMakeScale(1.0, 1.0); toViewController.view.alpha = 1.0f; fromViewController.view.alpha = 0.0f; } completion:^(BOOL finished) { fromViewController.view.transform = CGAffineTransformIdentity; [transitionContext completeTransition:![transitionContext transitionWasCancelled]]; }]; } - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext { return 3.0f; }

STEP4: 在FirstViewController中實現UINavigationControllerDelegate的一些方法

#import "PushAnimation.h" @interface FirstViewController : UIViewController <UINavigationControllerDelegate> @property (nonatomic, strong) PushAnimation *animation;

- (void)viewDidLoad { [super viewDidLoad]; _animation = [PushAnimation new]; //隱藏NavigationBar self.navigationController.navigationBarHidden = YES; //設置背景圖片 UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.view.frame]; [imageView setImage:[UIImage imageNamed:@"1.jpg"]]; [self.view addSubview:imageView]; //定義一個button UIButton *pushBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; pushBtn.frame = CGRectMake(284, 700, 200, 40); [pushBtn setTitle:@"push" forState:UIControlStateNormal]; pushBtn.titleLabel.font = [UIFont systemFontOfSize:32.0f]; [pushBtn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:pushBtn]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.navigationController.delegate = self; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if (self.navigationController.delegate == self) { self.navigationController.delegate = nil; } } - (void)buttonClicked:(id)sender { SecondViewController *presentController = [[SecondViewController alloc]init]; [self.navigationController pushViewController:presentController animated:YES]; } #pragma mask UINavigationControllerDelegate - (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC { if (operation == UINavigationControllerOperationPush) { return self.animation; } return nil; }

STEP5: 在SecondViewController中調用PopAnimation動畫


@interface SecondViewController : UIViewController <UINavigationControllerDelegate> @property(nonatomic, strong) PopAnimation *animation;

- (void)viewDidLoad { [super viewDidLoad]; _animation = [PopAnimation new]; //隱藏NavigationBar self.navigationController.navigationBarHidden = YES; //設置背景圖片 UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.view.frame]; [imageView setImage:[UIImage imageNamed:@"2.jpg"]]; [self.view addSubview:imageView]; //定義一個button UIButton *pushBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; pushBtn.frame = CGRectMake(284, 700, 200, 40); [pushBtn setTitle:@"Pop" forState:UIControlStateNormal]; pushBtn.titleLabel.font = [UIFont systemFontOfSize:32.0f]; [pushBtn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:pushBtn]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.navigationController.delegate = self; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if (self.navigationController.delegate == self) { self.navigationController.delegate = nil; } } - (void)buttonClicked:(id)sender { [self.navigationController popViewControllerAnimated:YES]; } #pragma mask UINavigationControllerDelegate - (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC { if (operation == UINavigationControllerOperationPop) { return self.animation; } return nil; }

STEP6:  Over 了


源碼下載地址: http://download.csdn.net/detail/luozhonglan/7979545

***************************************************************************************************************************************************************************************













生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 免费日韩一区二区三区 | 久久免费少妇高潮久久精品99 | 精品一区二区三区国产 | 久久综合九九 | 精品久久久久久久久久久久久久久 | 欧美日韩国产色综合一二三四 | 小草av| 日韩精品视频在线免费观看 | 亚洲视频在线观看网址 | 精品九九久久 | 黄色免费高清视频 | 国产日产欧美一区二区 | 青青视频一区二区 | 韩日一级 | 四虎www4hu永久免费 | 国产一区二区三区在线观看免费 | 久久久久久国产精品美女 | 色玖玖| 国产精品久久久久永久免费观看 | www.99精品 | 久久成人精品 | 成人午夜在线视频 | 国产成人在线一区 | 九色av| 日韩在线综合 | 日韩av黄色 | 韩日欧美 | 亚洲国产精品成人天堂 | 久久久久久毛片免费看 | 国产午夜免费 | 国产乱码精品1区2区3区 | 色精品 | 久久aa| 中文字幕亚洲视频 | 国产精品爽爽爽爽爽爽在线观看 | 91偷拍一区二区三区精品 | 欧美色综合一区二区三区 | 亚洲一区二区中文字幕 | 嫩草午夜 | 国产精品久久久av久久久 | 久久av中文 |