多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > 互聯(lián)網(wǎng) > iOS7使用代理自定義導(dǎo)航轉(zhuǎn)場(chǎng)動(dòng)畫

iOS7使用代理自定義導(dǎo)航轉(zhuǎn)場(chǎng)動(dòng)畫

來源:程序員人生   發(fā)布時(shí)間:2014-10-10 08:00:01 閱讀次數(shù):3301次

如果你已經(jīng)厭倦了使用UINavigationController進(jìn)行簡(jiǎn)單粗暴的push和pop轉(zhuǎn)場(chǎng)操作,你完全可以使用自定義的導(dǎo)航轉(zhuǎn)場(chǎng)效果,iOS7提供了許多漂亮的代理方法幫助你實(shí)現(xiàn)各種自定義動(dòng)畫,下面演示一個(gè)簡(jiǎn)單的導(dǎo)航轉(zhuǎn)場(chǎng)動(dòng)畫Demo的實(shí)現(xiàn)過程,效果如圖一所示:




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


STEP2:使用UIViewControllerAnimatiedTransitioning代理方法自定義Push 動(dòng)畫

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

@interface PushAnimation : NSObject <UIViewControllerAnimatedTransitioning>
2.)PopAnimation的實(shí)現(xiàn)


- (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 動(dòng)畫

@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中實(shí)現(xiàn)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; //設(shè)置背景圖片 UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.view.frame]; [imageView setImage:[UIImage imageNamed:@"1.jpg"]]; [self.view addSubview:imageView]; //定義一個(gè)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中調(diào)用PopAnimation動(dòng)畫


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

- (void)viewDidLoad { [super viewDidLoad]; _animation = [PopAnimation new]; //隱藏NavigationBar self.navigationController.navigationBarHidden = YES; //設(shè)置背景圖片 UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.view.frame]; [imageView setImage:[UIImage imageNamed:@"2.jpg"]]; [self.view addSubview:imageView]; //定義一個(gè)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

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













生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 国产精品久久99 | 欧美最猛黑人xxxxx猛交 | 欧美精品亚洲精品日韩专区 | 综合久久久 | 一级做a爰片久久毛片潮喷 一级做a爰片久久毛片看看 | 欧美久久久久久久一区二区三区 | 精品视频一区二区三区免费 | 亚洲天堂免费观看 | 99影视在线视频免费观看 | 韩国三级一线观看久 | 全网免费在线播放视频入口 | 亚洲综合日韩欧美一区二区三 | 妇欲欢公爽公妇高h欲 | 欧美交性 | 与黑人女人做爰的真实感受 | 国产最新进精品视频 | 日本成本人在线观看免费视频 | 亚洲免费在线视频 | 久久国产免费福利资源网站 | 久久天堂色 | porn在线视频一区二区 | 手机看片高清日韩精品 | 久久精品一品道久久精品9 久久精品一区二区 | 成人久久伊人精品伊人 | 免费看成人国产一区二区三区 | 最近的中文字幕免费视频1 最近的中文字幕免费完整 最近的中文字幕视频大全高清 | 亚洲一区二区三区在线 | 亚洲精品国产精品国自产网站 | 亚洲综合日韩精品欧美综合区 | 亚洲视频 中文字幕 | 大学生一级毛片高清版 | 顶级欧美色妇xxxxbbbb | 一区二区三区在线免费 | 毛色毛片免费观看 | 亚洲午夜久久久精品影院视色 | 女性一级全黄生活片 | 日本特黄一级大片 | 免费观看男女羞羞的视频网站 | 99精品欧美一区二区三区 | 久久嫩草 | 欧美成人免费全部观看天天性色 |