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'
Rather than ever hard coding a width 320, you should always determine at run time, e.g. src.view.frame.size.width.
I’m surprised you were ok with the portrait presentation, as on my device, the old view is blinked out.
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:
If you wanted more of a push, I generally just change frames/centers, e.g., you could do something like: