简体   繁体   English

在没有导航控制器的情况下更改具有平滑推送过渡的视图控制器

[英]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.

相关问题 如何在没有NavigationController的情况下推送子ViewController? - How to push sub-ViewControllers without NavigationController? 如何在 navigationController 堆栈上使用多个 viewController 弹出ToRootViewController 并仅显示一个转换? - How to popToRootViewController with multiple viewControllers on the navigationController stack and show only one transition? 在iOS 9上使用NavigationController进行推送动画的自定义转换 - Custom transition for push animation with NavigationController on iOS 9 如何在没有navigationController的情况下过渡到根视图控制器? - How to transition to root view controller without navigationController? 动画NavigationController过渡而不动画导航栏 - Animate NavigationController transition without animating navigation bar 如何在UIViewController上不使用NavigationController的情况下推送DetailView - How to push DetailView without NavigationController on UIViewController 更改导航栏“prefersLargeTitles”时的平滑过渡 - Smooth transition when changing navigation bar "prefersLargeTitles" 在setViewControllers之后navigationController.viewControllers为0 - navigationController.viewControllers is 0 after setViewControllers 在不使用navigationController的情况下添加过渡效果-iOS - Add Transition effect without using navigationController- IOS 迅速。 在ViewController之间进行转换,而不会回退 - Swift. Transition between ViewControllers without dismissing them on going back
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM