iOS分享扩展仅支持竖屏模式

3

我需要将我的共享扩展限制为仅支持竖屏模式。但是目前似乎不行,有没有办法实现呢?

@implementation UINavigationController

-(BOOL)shouldAutorotate
{
     return UIInterfaceOrientationMaskPortrait;
}

-(NSUInteger)supportedInterfaceOrientations
{
     return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
     return UIInterfaceOrientationPortrait;
}

你能实现这个吗? - Zoeb S
1个回答

1

你可以扩展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;

}


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接