[英]How to push sub-ViewControllers without NavigationController?
最近,我在UIView中找到了一种方法,该方法可为切换视图带来“推入或弹出”感觉。
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion
这完全脱离了UIView文档,因此,我建议您查看UIView类参考以了解具体信息。 基本上,它将视图切换到另一个视图,而options:
部分可让您从多种不同的样式中进行选择。
我实际上是通过玩UIView动画来解决的。
-(void)slideInView:(UIView*)newView toView:(UIView*)oldView {
/* Sets the view outside the right edge and adds it to mainView */
newView.bounds = mainView.bounds;
newView.frame = CGRectMake(newView.frame.origin.x + 784, newView.frame.origin.y, newView.frame.size.width, newView.frame.size.height);
[mainView addSubview:newView];
/* Begin transition */
[UIView beginAnimations:@"Slide Left" context:oldView];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:0.0f];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDidStopSelector:@selector(slideInCompleted:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
newView.frame = CGRectMake(0,0, newView.frame.size.width, newView.frame.size.height);
oldView.frame = CGRectMake(oldView.frame.origin.x - 784, oldView.frame.origin.y, oldView.frame.size.width, oldView.frame.size.height);
[UIView commitAnimations];
}
-(void)slideInCompleted:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
UIView *view = (UIView*)context;
[view removeFromSuperview];
}
并使用它
menuController = [[MenuViewController alloc] init];
[self slideOutView:menuController.view toView:loginController.view];
[oldController release];
记住已经分配了一个UIViewController,在使用完它后就需要释放它! 在示例中,我完成了loginController并将其释放。
没有UINavigationController
绝对没有办法在本地 “推送”任何控制器。 但是,您可以为视图设置动画。
对于您发布的示例,看起来简单的UIScrollView
似乎是您最简单的选择。
我将使用UIScrollView,因为它可以捕捉到内置的“页面”。您也可以使用setContentOffset:animated:滚动到任何部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.