【发布时间】:2010-04-27 00:33:00
【问题描述】:
这是一个我无法弄清楚如何工作的流程。 (当我声明(工作)时,这意味着在当前状态下,该视图的方向规则正常工作)
第一个视图:UINavigationController 堆栈上的 TableView,它是 UITabBarController 的选项卡。
TableView 只能是纵向的。 (在职的) 当您将 TableView 旋转为横向时,模态会出现一个自定义 UIView,它就像一个封面流(我稍后会解释那里的问题)。
在 tableview 上进行的选择会将 UIScrollview 推入堆栈。
UIScrollView 允许所有方向。 (工作)
当 UIScrollView 处于横向模式并且用户回击时,他们将被带到自定义 UIView,这类似于封面流并且只允许横向。
问题就在这里。因为 UIScrollView 允许完全旋转,所以它允许 TableView 旋转以及横向。
我有一个附加到通知“UIDeviceOrientationDidChangeNotification”的方法,该方法检查自定义视图是否是当前控制器,如果是,如果用户已旋转回纵向,我需要弹出自定义视图并显示表格查看。
表格视图必须旋转回纵向,只要用户看不到它就可以了。当我创建自定义动画时,它的效果非常好,除了一些奇怪的不可见黑框,它似乎在我将自定义视图淡出到 tableview 之前随着设备旋转。
进一步为了确保我的 tableview 将旋转到纵向,我必须允许 customview 支持所有方向,因为系统会查看当前视图(在我的代码中)是否允许该应用旋转到一定的方向。因此,我提出的许多解决方案都会在表格视图重新聚焦时显示 customview 旋转为纵向。
我的另一个问题非常相似。如果您正在查看 tableview 并旋转 customview 的 modalview 。当您在此视图上进行选择时,它会将 UIScrollview 推送到堆栈上,但由于 Tableview 仅支持纵向,因此 UIScrollview 在设备处于横向模式时以纵向显示。
我怎样才能克服这些可怕的障碍?
这是我目前的尝试:
在使用 UITabBarController 时,系统实际上只关心 tabbarcontroller 对旋转的看法。
目前,每当加载视图时,它都会报告它支持的方向。
TabBarController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
switch (self.supportedOrientation) {
case SupportPortraitOrientation:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
return (interfaceOrientation == UIInterfaceOrientationPortrait);
break;
case SupportPortraitUpsideDownOrientation:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
break;
case SupportPortraitAllOrientation:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
break;
case SupportLandscapeLeftOrientation:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
break;
case SupportLandscapeRightOrienation:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
break;
case SupportLandscapeAllOrientation:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
break;
case SupportAllOrientation:
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
}else {
//[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
}
return YES;
break;
default:
return (interfaceOrientation == UIInterfaceOrientationPortrait);
break;
}
}
此代码块是我的 UINavigationController 的一部分,并且位于响应 UIDeviceOrientationDidChangeNotification 通知的方法中。它负责弹出customview并显示tableview。有两个不同的版本,最初用于两个不同版本的 SDK,但两者都非常接近解决方案。
第一个在 3.0 上不受支持的原因是由于某种原因您不能让视图显示然后显示为模态视图。不确定这是错误还是功能。
第二种解决方案效果很好,只是我看到一个外盒围绕着 iphone 旋转。
if ([[self topViewController] isKindOfClass:FlowViewController.class]) {
NSString *iphoneVersion = [[UIDevice currentDevice] systemVersion];
double version = [iphoneVersion doubleValue];
if(version > 3.0){ //1st solution
//if the delivered app is not built with the 3.1 SDK I don't think this will happen anyway
//we need to test this
[self presentModalViewController:self.flowViewController animated:NO];
//[self toInterfaceOrientation:UIDeviceOrientationPortrait animated:NO];
[self popViewControllerAnimated:NO];
[self setNavigationBarHidden:NO animated:NO];
[self dismissModalViewControllerAnimated:YES];
}else{ //2nd solution
DLog(@"3.0!!");
//[self toInterfaceOrientation:UIDeviceOrientationPortrait animated:NO];
CATransition *transition = [CATransition animation];
transition.duration = 0.50;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFade;
CATransition *tabBarControllerLayer = [CATransition animation];
tabBarControllerLayer.duration = 0.50;
tabBarControllerLayer.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
tabBarControllerLayer.type = kCATransitionPush;
tabBarControllerLayer.subtype = kCATransitionFade;
[self.tabBarController.view.layer addAnimation:transition forKey:kCATransition];
[self.view.layer addAnimation:transition forKey:kCATransition];
[self popViewControllerAnimated:NO];
[self setNavigationBarHidden:NO animated:NO];
}
[self performSelector:@selector(resetFlow) withObject:nil afterDelay:0.75];
}
我几乎确信除了手动旋转会打乱键盘旋转之外没有其他解决方案。
任何建议将不胜感激!
谢谢。
【问题讨论】:
标签: iphone uinavigationcontroller uitabbarcontroller rotation orientation