本文共 1528 字,大约阅读时间需要 5 分钟。
1. 如果没有在Navi中, 则使用下面三个方法来决定屏幕的旋转方向。 同样, 对针present出来的VC也用下面的方法来决定
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
returnUIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientation {
returnUIInterfaceOrientationMaskPortrait;
}
3. 如果在Navi中, 又想Navi下的VC自己去控制自己的屏幕旋转, 可以在Navi中如下实现,然后在自己的VC中分别控制屏幕的旋转, 实现后发现还是有些问题。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [self.topViewControllershouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewControllersupportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
returnUIInterfaceOrientationPortrait;
}
4. 建议还是在Navi中来限制屏幕的旋转, 然后控制特别需要旋转的界面的弹出方式为present
5. 对于某些界面,以present出来的界面为例, 如果需要针对某些条件来设置屏幕朝向, 可以如下代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (self.forVedioPlayer == YES) {
return YES;
}else {
return NO;
}
}
-(NSUInteger)supportedInterfaceOrientations
{
if (self.forVedioPlayer == YES) {
return UIInterfaceOrientationMaskLandscape;
}else {
return UIInterfaceOrientationMaskPortrait;
}
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if (self.forVedioPlayer == YES) {
return UIInterfaceOrientationLandscapeLeft;
}else {
return UIInterfaceOrientationPortrait;
}
}
下面这篇文章讲得较好,http://blog.sina.com.cn/s/blog_76264a170101e5lb.html
转载地址:http://txwpi.baihongyu.com/