Frage

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. I have made a simple illustration of what I want in my iPhone app.

enter image description here --> enter image description here --> enter image description here --> enter image description here

I am using storyboard and developing for iOS 6 and higher. I'm not using segues. Currently I'm using this code to change from view1 to view2 without any animations in Xcode:

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

NOTE: I am not using NavigationControllers! Just normal 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. Without having to delete my UIViewController and build it again only using 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!

War es hilfreich?

Lösung

Set animation for the 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. You need to handle the background view(view1) during the animation.

I have used this code in my app, and it's working fine for me.

Andere Tipps

Consider using container view controllers. Here is a tutorial: http://www.cocoanetics.com/2012/04/containing-viewcontrollers/

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top