开发者

iphone navigation model without uinavigation controller?

I am writing an app that needs to display a series of approximately 10-20 'views'. I have 4 view controllers and nibs that I would like to use. Each view has a forward and back button on it and the views should slide in either from the right or the left depending on the button pushed. I want to be able to reuse the nibs and controllers to present the information. I was trying to use a uinavigation controller, but ran into the problem that you can't push a view onto the stack more than once. The overall structu开发者_Go百科re is a uinavigationcontroller within a tabbarcontroller. Is there a way to do this with a uinavigation controller, or should I try a different approach.


I would suggest making a container view controller class. It would create and "own" the four different view controllers you want to use. Then use something like this to switch between them:

// 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"];

(stolen from here)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜