我正在编写一个需要显示一系列大约10-20个“视图”的应用程序。我有4个视图控制器和笔尖,我想使用它。每个视图上都有一个前进和后退按钮,视图应该从右侧或左侧滑动,具体取决于按下的按钮。我希望能够重用nib和控制器来呈现信息。我试图使用uinavigation控制器,但遇到的问题是你不能多次将视图推入堆栈。整体结构是tabbarcontroller中的uinavigationcontroller。有没有办法用uinavigation控制器做这个,或者我应该尝试不同的方法。
答案 0 :(得分:2)
我建议制作容器视图控制器类。它将创建并“拥有”您想要使用的四个不同的视图控制器。然后使用这样的东西在它们之间切换:
// get the view that's currently showing
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view view
UIView *theWindow = [currentView superview];
// remove the current view and replace with newView
[currentView removeFromSuperview];
[theWindow addSubview:newView];
// set up an animation for the transition between the views
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
(从here被盗)