內容來源
https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/UsingSegues.html#//apple_ref/doc/uid/TP40007457-CH15-SW1
The Life Cycle of a Segue
segue對象是UIStorybaordSegue或它的子類的實例卸奉。你的app不會直接的創(chuàng)建它梗劫。UIKit會在segue被觸發(fā)時創(chuàng)建它拭荤。
- 被呈現的view controller被創(chuàng)建并初始化插勤。
- segue被創(chuàng)建谍肤,并且它的initWithIdentifier:source:destination:被調用琅关。identifier 是在interface builder里你提供給segue的唯一標識煮岁。別兩個參數是過渡過程里的controller對象。
- presenting view controller的prepareForSegue:sender: 被調用涣易。
- segue對象的 perform 方法 被調用画机。這個方法是執(zhí)行轉換過程,把新的 view controller放到屏幕上來新症。(是不是可以在這里面加自定義的轉換效果步氏。)
- segue的引用被釋放掉。
實現自定義的Segue
為了實現自定義的segue,繼承UIStoryboardSegue類徒爹,并實現以下方法:
- 覆蓋initWithIdentifier:source:destination:方法荚醒,用它初始化你自定義的segue.總是先調用super.
- 實現 perform 方法,并用它配置您自己的過渡動畫隆嗅。
注意:
如果你為了配置segue增加了一些屬性界阁,你不能在interface builder里的配置這些屬性。你可以在觸發(fā)segue的view controller的prepareForSegue:sender:配置它們榛瓮。
- (void)perform {
// Add your own animation code here.
[[self sourceViewController] presentViewController:[self destinationViewController] animated:NO completion:nil];
}