我有一個使用我的showNewView方法通過我的主UIViewController(稱爲MainUIVC)加載的UIViewController(稱爲SubUIVC),當我完成SubUIVC時,使用goBack返回MainUIVC方法。如何在removefromsuperview後執行方法
我希望做的是在MainUIVC執行一些代碼一次GoBack方法完成,我的MainUIVC.view已經加載。
任何人都可以幫助我做到這一點?以下是我上面提到的兩種方法。
-(void) showNewView:(UIViewController*)showView{
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];
UIView *newView = showView.view;
// remove the current view and replace with newView
[theWindow addSubview:newView];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:WIPE_ANIMATION_DURATION];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToNewView"];
}
-(IBAction)goBack:(id)sender{
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];
// remove the current view and replace with superview
[currentView removeFromSuperview];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:WIPE_ANIMATION_DURATION];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToNewView"];
}
爲什麼不ü用persentModalView或navigationController的櫃面 - pushViewController和SubUIVC的viewDidDisappear編寫代碼。這將是顯示viewController視圖的理想方法。 – samfisher
該代碼需要在MainUIVC中執行,因爲它是在SubUIVC完成其工作後對視圖的操縱 – Vince613