如何在removefromsuperview后执行方法
我有一个 UIViewController(称为 SubUIVC),它是使用 showNewView 方法通过我的主 UIViewController(称为 MainUIVC)加载的,当我完成 SubUIVC 时,我使用 goBack 方法返回到 MainUIVC。
我想做的是在 goBack 方法完成并且我的 MainUIVC.view 已加载后执行 MainUIVC 中的一些代码。
谁能帮我做这个吗?下面是我上面参考的两种方法。
-(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"];
}
I have a UIViewController (call it SubUIVC) that was loaded via my main UIViewController (call it MainUIVC) using my showNewView method and when I am done with the SubUIVC, I return to MainUIVC using my goBack method.
What I'd like to do is execute some code in MainUIVC once the goBack method is completed and my MainUIVC.view has been loaded.
Can anyone help me with doing this? Below are the two methods I made reference to above.
-(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"];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MainController 中有一个 BOOL 属性,而不是由 goBack: 函数设置的 get 属性。
在主控制器的 viewDidAppear: 中,检查 BOOL 以查看视图是否因 goback: 被调用而刚刚出现,然后执行您的操作。显然你应该重置该标志。
Have a BOOL property in the MainController than get's set by the goBack: function.
In the main controller's viewDidAppear:, check that BOOL to see if the view's just appeared as a result of goback: being called and do your thing. Obviously you should then reset that flag.