我的应用程序中有一个scrollview,第二个滚动到我的scrollview的最后一页我被segued到tableviewcontroller。
但是为了在从scrollview跳转到tableview控制器时实现“像动画一样分页”,我扩展了UIStoryboardSegue类并实现了这样的perform方法:
- (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);
}
];
}
当用户处于UIInterfaceOrientationPortrait方向时,它就像一个魅力。但是当我切换到UIInterfaceOrientationLandscapeLeft或者右边时,我无法让它工作。
我基本上想要做的是是执行segue所以看起来tableviewcontroller从左侧进入主屏幕(不是从顶部或底部进入,因为它是默认行为)像上面的代码适用于正常方向。我认为解决方案是这样的:
- (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);
}
}
];
}
但是我觉得更难,任何帮助都是适当的。
问题更新:
我现在尝试了这个:
- (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];
}
我收到以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
答案 0 :(得分:2)
您应该始终在运行时确定宽度320,而不是硬编码320。 src.view.frame.size.width。
我很惊讶你的肖像演示没问题,就像在我的设备上一样,旧视图眨了眨眼。
似乎你的新尝试是一个非常不同的外观(翻转而不是推动)。你想要哪种效果?
如果您想要翻转,可以执行以下操作:
[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];
}];
如果您想要更多推动,我通常只需更改框架/中心,例如,您可以执行以下操作:
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];
}
];