我需要将共享扩展限制为仅限纵向模式。但到目前为止,这还不行。有办法吗?
@implementation UINavigationController
-(BOOL)shouldAutorotate
{
return UIInterfaceOrientationMaskPortrait;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
答案 0 :(得分:1)
您可以像answer here
一样扩展UIScreen并在
中表演 - (void)viewDidLayoutSubviews of UIViewController.
中的内容
来自第一个链接的代码与Objective-C中的代码相似:
- (UIInterfaceOrientation) orientation {
CGPoint p = [self.coordinateSpace convertPoint: CGPointZero toCoordinateSpace: self.fixedCoordinateSpace];
if (CGPointEqualToPoint(p, CGPointZero)) {
return UIInterfaceOrientationPortrait;
} else {
if (p.x != 0 && p.y != 0) {
return UIInterfaceOrientationPortraitUpsideDown;
} else {
if (p.x == 0 && p.y != 0) {
return UIInterfaceOrientationLandscapeLeft;
} else {
if (p.x != 0 && p.y == 0) {
return UIInterfaceOrientationLandscapeRight;
} else {
return UIInterfaceOrientationUnknown;
}
}
}
}
return UIInterfaceOrientationUnknown;
}