这是在 tabviewcontroller 的 Uiview 和新的 uiview 之间进行转换所需的代码。代码转到一个按钮的 IBAction,它存在于 tabviewcontroller 的一个 uiview 中。
//初始化应用委托
AppDelegate appDelegate = (AppDelegate) [[UIApplication sharedApplication] 委托];
// 获取当前显示的视图
UIView *currentView = self.view;
// 获取底层的UIWindow,或者包含当前视图视图的视图
UIView *theWindow = [currentView superview];
// remove the current view and replace with mynewView1
[currentView removeFromSuperview];
//将新视图分配给viewcontroller1。它是uitabbarcontroller的第一个uiviewcontroller。我的 uitabbarcontroller 在我的项目中由五个 uiviewcontroller 组成。
该按钮存在于第一个 viewcontroller1 中,这就是我将新视图分配给 viewcontroller1 的原因。如果从我的 uitabbarcontroller 的 secondviewcontroller (viewcontroller2) 按下按钮,我会将新视图分配给 secondviewcontroller (viewcontroller2) 等等...
appDelegate.viewController1=[[MyMessages alloc] initWithNibName:@"MyMessages" bundle:nil];
//将其添加到窗口中
[theWindow addSubview:appDelegate.viewController1.view];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
感谢您的帮助!我已经尝试了一天多来实现它。我希望它能帮助遇到同样问题的人。