The rotation is interrupted when trying

I have scrollview in my application, and the second I scroll to the last page of my scrollview, which I separate from tableviewcontroller.

But to achieve "paging animation" when moving from scrollview to a table view controller, I expanded the UIStoryboardSegue class and implemented this method:

- (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 the user is in the UIInterfaceOrientationPortrait orientation. But when I switch to UIInterfaceOrientationLandscapeLeft or right, I cannot get it to work.

What I basically want to do here is to do a segue, so it looks like the tableviewcontroller element is entering from the left side of the main screen (not top or bottom, as this is the default behavior) as the code above works for normal orientation. I assumed that the solution would be 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, although I’m still helping.

question:

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 the following error:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported' 
+4
source share
1 answer
  • Instead of hard coding a width of 320, you should always determine at runtime, for example. src.view.frame.size.width.

  • I am surprised that you were fine with the presentation in the portrait, because on my device the old view is blinked.

  • It seems that your new attempt is a completely different look (flipping, not tapping). What effect are you going to deal with?

If you want to flip, you can 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 want to click more, I usually just change the frames / centers, for example, you can 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]; } ]; 
+2
source

All Articles