【问题标题】:ios share extension portrait onlyios仅共享扩展肖像
【发布时间】:2016-01-29 01:48:31
【问题描述】:
我需要将我的共享扩展程序限制为仅处于纵向模式。但到目前为止,还不行。有办法吗?
@implementation UINavigationController
-(BOOL)shouldAutorotate
{
return UIInterfaceOrientationMaskPortrait;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
【问题讨论】:
标签:
ios
orientation
ios8-share-extension
【解决方案1】:
你可以扩展 UIScreen,比如answer here
并在其中执行
- (void)viewDidLayoutSubviews of UIViewController.
类似answer here的东西
第一个链接中的代码与 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;
}