文章出處

iOS開發 跳轉場景的三種方式

假設A跳轉到B,三種方法:
1.按住ctrl鍵,拖動A上的控件(比如說UIButton)到B上,彈出菜單,選擇Modal.不需要寫任何代碼,在A上點擊Button就會跳轉到B
2. 按住ctrl鍵,拖動A上的View Controller到B上,彈出菜單,選擇Modal,兩個場景間自動添加連接線和圖標,選中該圖標,打開Storyboard Segue,identifier輸入一個標識符,這里以”aaaa”為例.A里需要跳轉時,執行下面的代碼:

1
 [self performSegueWithIdentifier:@"aaaa" sender:self];

3.完全用代碼來實現,代碼如下:

1
2
3
4
5
6
7
8
9
    //先獲取UIStoryBoard對象,參數為文件名
    UIStoryboard *mainStoryBoard=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    //獲取SecondViewController實例,參數是StoryBoard ID,選中View Controller,在Identity Inspector中
    SecondViewController *second=[mainStoryBoard instantiateViewControllerWithIdentifier:@"second"];
    //設置過渡的樣式,和顯示的樣式
    second.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
    second.modalPresentationStyle=UIModalPresentationFormSheet;
    //顯示
    [self presentViewController:second animated:YES completion:nil];

文章列表


不含病毒。www.avast.com
全站熱搜
創作者介紹
創作者 大師兄 的頭像
大師兄

IT工程師數位筆記本

大師兄 發表在 痞客邦 留言(0) 人氣()