[英]Changing viewcontrollers with smooth push transition and without navigationcontroller
I'm trying to change from viewcontroller
view1 to viewcontroller
view2 with a smooth and nice transition, where view1 gets pushed to the left by view2 within a second.我正在尝试从
viewcontroller
view1 更改为viewcontroller
view2 平滑而漂亮的过渡,其中 view1 在一秒钟内被 view2 推到左边。 I have made a simple illustration of what I want in my iPhone app.我已经简单地说明了我想要的 iPhone 应用程序。
-->
-->
-->
-->
-->
-->
I am using storyboard and developing for iOS 6 and higher.我正在使用故事板并为 iOS 6 及更高版本进行开发。 I'm not using segues.
我没有使用segues。 Currently I'm using this code to change from view1 to view2 without any animations in Xcode:
目前我正在使用此代码在 Xcode 中没有任何动画的情况下从 view1 更改为 view2:
SecondViewController *viewTwo = [self.storyboard instantiateViewControllerWithIdentifier:@"View2"];
[self presentViewController:viewTwo animated:NO completion:nil];
I am looking for code that can replace my existing code with.我正在寻找可以替换我现有代码的代码。 Code that changes from view1 to view2 with the push transition
通过推送转换从 view1 更改为 view2 的代码
NOTE : I am not using NavigationControllers
!注意:我没有使用
NavigationControllers
! Just normal ViewControllers
.只是普通的
ViewControllers
。 I would prefer to do this with codes.我更愿意用代码来做到这一点。
EDIT : I understand that this would be very easy to do if I used a navigation controller, but the problem is that I'm done building the storyboard and I have already buildt everything using normal view controller.编辑:我知道如果我使用导航控制器,这将很容易做到,但问题是我已经完成了故事板的构建,而且我已经使用普通视图控制器构建了所有内容。 And that creates my second question:
这就产生了我的第二个问题:
Are there any way I can simply convert my UIViewControllers
to work as UINavigationControllers
.有什么方法可以简单地将我的
UIViewControllers
转换为UINavigationControllers
。 Without having to delete my UIViewController
and build it again only using UINavController
?不必删除我的
UIViewController
并仅使用UINavController
重新构建它?
ANSWER : I solved my problem by implementing a navigation controller to my project.答案:我通过在我的项目中实现导航控制器解决了我的问题。 I have totally misunderstood the whole concept of navigations controllers earlier, but I have now figured it out.
我之前完全误解了导航控制器的整个概念,但现在我已经弄清楚了。 So my problem is solved!
所以我的问题解决了!
Set animation for the view2.为 view2 设置动画。 Use this code.
使用此代码。
-(void)ViewNavigationOnLeftTabs
{
self.view.frame=CGRectMake(420, 0,self.view.frame.size.width,self.view.frame.size.height);
[UIView beginAnimations:@"Anim2" context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
self.view.frame=CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height);
[UIView commitAnimations];
}
-(IBAction)nextView
{
SecondViewController *sampleV=[[SecondViewController alloc] init];
[self.view addSubview:sampleV.view];
[self ViewNavigationOnLeftTabs];
}
Here I have added transition effect for the secondViewController exactly like your requirement.在这里,我按照您的要求为 secondViewController 添加了过渡效果。 You need to handle the background view(view1) during the animation.
您需要在动画期间处理背景视图(view1)。
I have used this code in my app, and it's working fine for me.我在我的应用程序中使用了这段代码,它对我来说很好用。
Consider using container view controllers.考虑使用容器视图控制器。 Here is a tutorial: http://www.cocoanetics.com/2012/04/containing-viewcontrollers/
这是一个教程: http : //www.cocoanetics.com/2012/04/ contains-viewcontrollers /
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.