到目前为止,我已经查看了每个问题,似乎没有人真正回答这个问题。
我创建了一个UITabBarController,并为其添加了几个视图控制器。大多数观点都是纵向观看的,但应该以横向观看。我不想使用加速度计或检测用户旋转设备的时间,我只想在横向选项卡中选择该视图时以横向模式显示视图。
我希望定时动画发生,例如标签丢失,视图旋转等,当他们选择该项目时,以及当他们选择不同的视图时发生相反的情况。
是否没有内置属性或方法告诉系统显示视图的方向是什么?
覆盖shouldautorotate ...方法到目前为止我做的一切都没有。
我不会欣赏的答案类型是“RTFM”,因为我已经拥有了,而且到目前为止为iPhone开发的任何人都知道,对于F-ing R来说,很少有用。
答案 0 :(得分:9)
论坛上的post可能有所帮助。简短的回答是,在viewWillAppear:方法
中绘制视图后,您必须手动旋转视图或控制器。CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +100.0);
[[appDelegate navController].view setTransform:landscapeTransform];
答案 1 :(得分:9)
以下是我要做的事情:
首先,将此定义放在文件的顶部,在#imports:
下#define degreesToRadian(x) (M_PI * (x) / 180.0)
然后,在viewWillAppear:方法
中[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
}
如果你想要动画,那么你可以将整个事物包装在一个动画块中,如下所示:
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
}
[UIView commitAnimations];
答案 2 :(得分:0)
覆盖控制器类中的Orientation方法并将其强制为横向,如下所示:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Overriden to allow any orientation.
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
简单高效!
答案 3 :(得分:0)
shouldAutorotateToInterfaceOrientation仅在tabbarcontroller中的所有视图或navigationcontroller中的所有视图控制器同意轮换时才起作用。