成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

ios5中UIViewController新使用方法

移動(dòng)開發(fā) iOS
下面詳細(xì)介紹一下addChildViewController,一個(gè)ViewController可以添加多個(gè)子ViewController,但是這些子ViewController只有一個(gè)是顯示到父視圖中的,可以通過transitionFromViewController:toViewController:duration:options:animations:completion:這個(gè)方法轉(zhuǎn)換顯示的子視圖。同時(shí)加入相應(yīng)的動(dòng)畫。

在iOS5中,ViewController中新添加了下面幾個(gè)方法:

  1. addChildViewController:  
  2. removeFromParentViewController  
  3. transitionFromViewController:toViewController:duration:options:animations:completion: 
  4. willMoveToParentViewController:  
  5. didMoveToParentViewController: 

下面詳細(xì)介紹一下addChildViewController,一個(gè)ViewController可以添加多個(gè)子ViewController,但是這些子ViewController只有一個(gè)是顯示到父視圖中的,可以通過transitionFromViewController:toViewController:duration:options:animations:completion:這個(gè)方法轉(zhuǎn)換顯示的子視圖。同時(shí)加入相應(yīng)的動(dòng)畫。下面以一個(gè)例子來說明,最后實(shí)現(xiàn)的效果:

image

點(diǎn)擊其中的按鈕如下:

imageimageimageimage

下面詳細(xì)介紹一下上述效果的實(shí)現(xiàn):

  1. 創(chuàng)建項(xiàng)目,changeViewController。
  2. 添加相應(yīng)的viewController,MainViewController、FirstViewController、SecondViewController、ThirdViewController。如下圖:

image

3.把MainViewController添加到window中。

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  2. {  
  3.     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  4.     // Override point for customization after application launch.  
  5.     MainViewController *mainViewController=[[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];  
  6.     self.window.rootViewController=mainViewController;  
  7.     [self.window makeKeyAndVisible];  
  8.     return YES;  

4.在MainViewController中添加三個(gè)按鈕,并且連接onClickbutton方法。

5.在MainViewController中添加三個(gè)子controller

  1. #pragma mark – View lifecycle - (void)viewDidLoad  
  2. {  
  3.     [super viewDidLoad];  
  4.     // Do any additional setup after loading the view from its nib.  
  5.      
  6.     FirstViewController *firstViewController=[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];  
  7.     [self addChildViewController:firstViewController];  
  8.      
  9.     SecondViewController *secondViewController=[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];  
  10.     [self addChildViewController:secondViewController];  
  11.      
  12.      
  13.     ThirdViewController *thirdViewController=[[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];  
  14.     [self addChildViewController:thirdViewController];  
  15.      
  16.     [contentView addSubview:thirdViewController.view];  
  17.     currentViewController=thirdViewController;  

其中要把其中的一個(gè)子controller的view添加到根視圖中,這樣才能顯示出相應(yīng)的視圖。

6.點(diǎn)擊按鈕,切換視圖。

  1. -(IBAction)onClickbutton:(id)sender  
  2. {  
  3.     FirstViewController *firstViewController=[self.childViewControllers objectAtIndex:0];  
  4.     ThirdViewController *thirdViewController=[self.childViewControllers objectAtIndex:2];  
  5.     SecondViewController *secondViewController=[self.childViewControllers objectAtIndex:1];  
  6.     if ((currentViewController==firstViewController&&[sender tag]==1)||(currentViewController==secondViewController&&[sender tag]==2) ||(currentViewController==thirdViewController&&[sender tag]==3) ) {  
  7.         return;  
  8.     }  
  9.     UIViewController *oldViewController=currentViewController;  
  10.     switch ([sender tag]) {  
  11.         case 1:  
  12.         {  
  13.             NSLog(@"留言及回復(fù)");  
  14.             [self transitionFromViewController:currentViewController toViewController:firstViewController duration:4 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{  
  15.             }  completion:^(BOOL finished) {  
  16.                 if (finished) {  
  17.                     currentViewController=firstViewController;  
  18.                 }else{  
  19.                     currentViewController=oldViewController;  
  20.                 }  
  21.             }];  
  22. }  
  23.             break;  
  24.         case 2:  
  25.         {  
  26.             NSLog(@"生日提醒");  
  27.             [self transitionFromViewController:currentViewController toViewController:secondViewController duration:1 options:UIViewAnimationOptionTransitionFlipFromTop animations:^{  
  28.                  
  29.             }  completion:^(BOOL finished) {  
  30.                 if (finished) {  
  31.                   currentViewController=secondViewController;  
  32.                 }else{  
  33.                     currentViewController=oldViewController;  
  34.                 }  
  35.             }];  
  36.         }  
  37.             break;  
  38.         case 3:  
  39.         {  
  40.             NSLog(@"好友申請(qǐng)");  
  41.             [self transitionFromViewController:currentViewController toViewController:thirdViewController duration:1 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{  
  42.                  
  43.             }  completion:^(BOOL finished) {  
  44.                 if (finished) {  
  45.                      currentViewController=thirdViewController;  
  46.                 }else{  
  47.                     currentViewController=oldViewController;  
  48.                 }  
  49.             }];  
  50.         }  
  51.             break;  
  52.         default:  
  53.             break;  
  54.     }  

其中我把按鈕設(shè)置成不同的tag了。

這時(shí)候點(diǎn)擊按鈕,就可以切換子視圖了。

這樣寫的好處: 多個(gè)UIViewController之間切換可以添加動(dòng)畫 當(dāng)內(nèi)存警告的時(shí)候,可以把當(dāng)前不是激活狀態(tài)的ViewController內(nèi)存釋放。

可以把代碼更好分開 項(xiàng)目源代碼:http://easymorse-iphone.googlecode.com/svn/trunk/changeViewController/

責(zé)任編輯:佚名 來源: 王軍的博客
相關(guān)推薦

2012-04-04 22:36:52

iOS5

2012-01-18 13:51:39

2018-06-20 10:34:56

堆棧iOSswift

2011-09-19 15:42:33

TwitteriOS5

2013-07-22 14:47:56

iOS開發(fā)iOS5中ASIHtt

2011-08-19 13:51:12

2011-08-09 14:25:43

蘋果iCloudiOS5

2013-07-25 14:12:53

iOS開發(fā)學(xué)習(xí)UITableView

2013-03-25 13:41:10

iOS5ARC內(nèi)存管理

2011-06-09 10:51:53

iPhone 3GSiOS5蘋果

2011-07-21 14:42:45

iOS UIViewCont 內(nèi)存

2011-08-16 14:59:31

IOS開發(fā)ViewDidUnloiOS 5

2010-10-08 14:27:25

JavascriptSplit

2011-06-14 10:18:58

QThread Qt 線程

2010-10-09 10:30:03

JS event

2012-05-27 20:21:40

2012-03-06 10:17:45

iOS SQLite3iOSSQLite3

2011-02-24 13:09:10

FireFTP

2012-01-13 09:55:54

jQuery

2011-08-10 16:08:02

iPhoneProtocol協(xié)議
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 久久久久久久一区 | 一级全黄少妇性色生活免费看 | 香蕉婷婷 | 日韩精品网站 | 第一福利社区1024 | 国产超碰人人爽人人做人人爱 | 亚洲欧美日韩精品久久亚洲区 | 一区二区国产精品 | 国产一级黄色网 | 亚洲精品日韩视频 | 午夜日韩视频 | 你懂的av| 性色的免费视频 | 特级做a爱片免费69 精品国产鲁一鲁一区二区张丽 | 日本一区二区高清不卡 | 美国av毛片 | 中文字幕动漫成人 | 懂色tv| 国外成人在线视频网站 | 欧美一区免费在线观看 | 日韩www| 中文字幕av在线 | 欧美福利在线 | 偷偷操视频| 亚洲国产精品久久久 | 国产精品黄色 | 欧美三区在线观看 | 亚洲视频一 | 成人国产免费视频 | 毛片.com | 日韩午夜 | 久久精品中文字幕 | 国产乱码精品一区二区三区五月婷 | 久久91 | 精品国产乱码久久久久久丨区2区 | 羞羞涩涩在线观看 | 亚洲三区在线 | 成人免费视频7777777 | 久久亚洲一区 | 精品在线一区 | 国产91丝袜在线播放 |