我尝试在ipad应用中禁用特定视图的自动旋转(用户看到的第一个视图),在视图的.m文件中我使用了以下代码:< / p>
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
// Return a bitmask of supported orientations. If you need more,
// use bitwise or (see the commented return).
return UIInterfaceOrientationMaskPortrait;
// return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
// Return the orientation you'd prefer - this is what it launches to. The
// user can still rotate. You don't have to implement this method, in which
// case it launches in the current orientation
return UIInterfaceOrientationPortrait;
}
然而,这似乎不起作用,因为视图仍然旋转到横向(见截图)
奇怪的是,上面的代码确实禁用了其他2个.xib视图的自动旋转。谁知道我做错了什么?
顺便说一下,这与应用程序提出的第一种观点有关,即:
我现在尝试使用下面的方法覆盖导航控制器方法,但仍然没有运气,视图仍在旋转! - 任何想法?
@interface CustomNavigationController : UINavigationController
@end
@implementation CustomNavigationController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
// Return YES for supported orientations
// return (interfaceOrientation != UIInterfaceOrientationMaskPortrait);
}
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
// Return a bitmask of supported orientations. If you need more,
// use bitwise or (see the commented return).
return UIInterfaceOrientationMaskPortrait;
// return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
// Return the orientation you'd prefer - this is what it launches to. The
// user can still rotate. You don't have to implement this method, in which
// case it launches in the current orientation
return UIInterfaceOrientationPortrait;
}
@end