Rotatation broken while trying to segue

I have a scrollview in my app and the second I scroll to the last page of my scrollview I get segued to tableviewcontroller.

But in order to achieve "paging like animation" when jumping from scrollview to tableview controller I extended UIStoryboardSegue class and implemented perform method like this :

- (void) perform {
    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;

    src.view.transform = CGAffineTransformMakeTranslation(0, 0);
    dst.view.transform = CGAffineTransformMakeTranslation(320, 0);

    [UIView animateWithDuration:0.3
                     animations:^{
                         [src presentModalViewController:dst animated:NO];
                         src.view.transform = CGAffineTransformMakeTranslation(320, 0);
                         dst.view.transform = CGAffineTransformMakeTranslation(0, 0);
                     }
     ];
}

And it works like a charm when user is in UIInterfaceOrientationPortrait orientation. But when I switch to UIInterfaceOrientationLandscapeLeft or right I can't get it to work.

What I basically want to do here is to perform segue so it looks like the tableviewcontroller is coming in from the left side onto the main screen (not from the top or bottom as it's default behavior) like the above code works for normal orientation. I've imagined solution to be something like this :

- (void) perform {
    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;


    if ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeLeft || [[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeRight){

    }else{
    src.view.transform = CGAffineTransformMakeTranslation(0, 0);
    dst.view.transform = CGAffineTransformMakeTranslation(320, 0);
    }
    [UIView animateWithDuration:0.3
                     animations:^{
                         [src presentModalViewController:dst animated:NO];
                         if ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeLeft || [[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeRight){
                         }else{
                         src.view.transform = CGAffineTransformMakeTranslation(320, 0);
                         dst.view.transform = CGAffineTransformMakeTranslation(0, 0);
                         }
                     }
     ];
}

But it's more difficult that I though, any help is appriciated.

question update :

I tried this now :

- (void) perform {
    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;

    [UIView transitionWithView:src.navigationController.view duration:0.3
                       options:UIViewAnimationTransitionFlipFromRight
                    animations:^{
                        [src.navigationController pushViewController:dst animated:YES];
                     }
     completion:NULL];
}

I get following error :

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'

Answers


  1. Rather than ever hard coding a width 320, you should always determine at run time, e.g. src.view.frame.size.width.

  2. I'm surprised you were ok with the portrait presentation, as on my device, the old view is blinked out.

  3. Seems like your new attempt is a very different look (flipping as opposed to pushing). Which effect are you going for?

If you want to flip, you could do something like:

[UIView animateWithDuration:0.5
                 animations:^{
                     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                     [sourceViewController.navigationController.view addSubview:destinationViewController.view];
                     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:sourceViewController.navigationController.view cache:NO];
                 }
                 completion:^(BOOL finished){
                     [destinationViewController.view removeFromSuperview];
                     [sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
                 }];

If you wanted more of a push, I generally just change frames/centers, e.g., you could do something like:

float width = sourceViewController.navigationController.view.frame.size.width;

CGPoint right = destinationViewController.view.center;
right.x += width;
destinationViewController.view.center = right;

[sourceViewController.navigationController.view addSubview:destinationViewController.view];

[UIView animateWithDuration:0.5
                 animations:^{
                     CGPoint left = sourceViewController.navigationController.view.center;
                     left.x -= width;
                     sourceViewController.navigationController.view.center = left;
                 }
                 completion:^(BOOL finished){
                     [destinationViewController.view removeFromSuperview];
                     [sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
                 }
 ];

Need Your Help

Infinite Scroll on Mobile browsers

javascript mobile infinite-scroll

I am trying to implement infinite scroll on my website and it works well on browsers on any computer, but it has issues on mobile browsers. So far, on chrome, if I don't zoom in or out it works ok...

What't the common way to support both PyQt4 and PyQt5 in one application?

python qt pyqt pyqt4 pyqt5

I want to make an application that will work with both PyQt4 and PyQt5.