1

I am using ViewControllers for my different views, this is currently how I am switching from page to page:

- (IBAction)switchToSecondPage:(id)sender 
{
    SecondPage * secondPage = [[SecondPage alloc] initWithNibName:nil bundle:nil];
    [self presentViewController: secondPage animated:YES completion:NULL];
}

This is the typical new view coming up from the bottom of the screen. I can use this to change the transition style, but I only get a couple choices to chose from, and none of them are any good.

secondPage.modalTransitionStyle = UIModalTransitionStylePartialCurl;

I am looking for transitions that are similar to the original one you get (page slides up from bottom). So I want 'slides down from top' and 'slides from left/right'. Is there any way I can do this. I see all sorts of applications doing this but I haven't been successful in finding anything.

PappaSmalls
  • 349
  • 2
  • 13

1 Answers1

0

One way to do this is,

  [self.view addSubview:secondPage.view];
  secondPage.view.frame = frameOutSideCurrentView;//Frame is set as outside the screen
  [UIView animateWithDuration:1.0f
                     animations:^{
                         //actual frame needed with an animation.
                         secondPage.view.frame = originalFrame;
                     }
                     completion:^(BOOL finished) { 
                        //if you need to anything specific once the animation is completed.
                     }];

Another way to do is by using this. TransitionController is custom implementation which helps to do this. In case you are facing issue with above code, use the category methods in this implementation. There are methods such as,

- (id)initWithViewController:(UIViewController *)viewController;
- (void)transitionToViewController:(UIViewController *)viewController
                     withOptions:(UIViewAnimationOptions)options;

which can be used to achieve this.

iDev
  • 23,310
  • 7
  • 60
  • 85
  • What do I put into frameOutsideCurrentView and originalFrame, everything i've tried gives errors. – PappaSmalls Nov 07 '12 at 23:35
  • For frameOutsideCurrentView, set a frame which is outside the current screen frame as CGRectMake(-320, 0, 320, 480); and while animating set originalFrame as CGRectMake(0, 0, 320, 480); This should animate from left to right. – iDev Nov 07 '12 at 23:37
  • The simulator runs but when I click the button nothing happens. Also, isn't this just using the same view? My second page opens a completely different UIViewController view. – PappaSmalls Nov 07 '12 at 23:48
  • Updated the answer. Check if the frame is set properly. Or else I would suggest you to use https://gist.github.com/1394947. Check this for how to use that, http://stackoverflow.com/a/8248284/1730272 – iDev Nov 07 '12 at 23:52
  • Wow thank you very much! It works perfectly, the only problem is that nothing on the second page works. If I click a button the simulator crashes and xcode will be highlighting "0x10dd09b: movl 8(%edx), %edi" – PappaSmalls Nov 08 '12 at 00:09
  • Never mind, I fixed it with adding " [self presentViewController: new animated:YES completion:NULL];" after completion:^(BOOL finished) { – PappaSmalls Nov 08 '12 at 00:12
  • @SinaYamani, If you are facing issues with that, try using TransitionController which I mentioned as second option. – iDev Nov 08 '12 at 05:04
  • The way I solved this problem causes further problems, it works fine for the first transition, but the second one automatically crashes. If I remove the code from after completion, I cannot interact with the new view. I will try using the TransitionController method now. – PappaSmalls Nov 08 '12 at 09:39
  • 1
    @SinaYamani, That is because your secondPage is getting released. You might have to declare it as `@property` and use it as self.secondPage instead of just secondPage. – iDev Nov 08 '12 at 09:42
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/19271/discussion-between-sina-yamani-and-acb) – PappaSmalls Nov 08 '12 at 09:58