Search code examples
iosanimationuiviewnavigationcontrollerpushviewcontroller

How to do "pushviewcontroller" animation WITHOUT using pushviewcontroller?


I want to do animation like NavigationController pushviewcontroller's animation. but I don't have a NavigationController, I don't want to make it.

So I want to ask is it possible to do it's animation in UIViewController? thanks!


oh forgot to say, I'm trying to switch view after clicking button. Using presentModalViewController now, but I don't like it's animation..


Solution

  • You could animate the origin property of your sub view, make it decreasing along the x axis just after adding it to the main view.

    EDIT :

    Use something like this :

    // retrieve the screen bounds
    CGRect sBounds = [[UIScreen mainScreen] bounds];
    // the origin point is just on the right of the screen
    CGRect newFrame = CGRectMake(sBounds.size.width,
                                 0.0,
                                 sBounds.size.width,
                                 sBounds.size.height);
    // set your view frame
    [mySecondView setFrame:newFrame];
    // add it to the main view
    [mainView addSubview:mySecondView];
    // then animate your view
    [UIView animateWithDuration:0.5     // set the interval you want
                     animations:^{
                         mySecondView.frame.origin = sBounds.origin;
                     }
    ];