强制UIActivityViewController以横向模式显示

时间:2015-01-27 04:32:47

标签: ios ios8 landscape uiactivityviewcontroller

我正在寻找一种强制UIActivityViewController以横向模式显示的方法。我的应用程序是专属的肖像除了图像VC推动横向图像全屏,从这里我希望用户能够在景观中启动UIActivityViewController(如下所示)...但是,它始终启动目前处于纵向模式。

Landscape Mode

我将shouldAutoRotate设置为NO,因为我需要自定义处理如何移动UI的某些部分旋转。我目前将preferredInterfaceOrientationForPresentation设置为UIInterfaceOrientationPortrait并尝试删除它,但似乎没有影响。理想情况下,我希望将此视图设置为UIInterfaceOrientationPortrait

我尝试设置状态栏(认为它是用来确定要启动的方向),但这也不起作用(下面的代码)。状态栏隐藏在此VC中。

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
[self setNeedsStatusBarAppearanceUpdate];

帮助我在横向模式下启动此菜单以及相应的用户选择的赏金时间(即,如果他们选择'消息'它也可以在横向模式下启动)。

以下是重新创建我所看到的代码的基础知识

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(launchShareMenu)];
[self.view addGestureRecognizer:singleTap];
}

-(BOOL)prefersStatusBarHidden{

return YES;
}


-(BOOL)shouldAutorotate {

return NO;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

return UIInterfaceOrientationPortrait;
}




- (void) launchShareMenu {

NSString *stringToShare = [NSString stringWithFormat:@"Share Me"];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[stringToShare] applicationActivities:nil];

NSArray *excludedActivities = @[UIActivityTypeAirDrop,
                                UIActivityTypePostToWeibo,
                                UIActivityTypeCopyToPasteboard,
                                UIActivityTypeSaveToCameraRoll,
                                UIActivityTypeAddToReadingList,
                                UIActivityTypePostToFlickr,
                                UIActivityTypePostToVimeo,
                                UIActivityTypePostToTencentWeibo];

controller.excludedActivityTypes = excludedActivities;

//Present controller
[self presentViewController:controller animated:YES completion:nil];
}

2 个答案:

答案 0 :(得分:0)

将它放在viewcontroller的viewDidLoad()

let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")

答案 1 :(得分:0)

您分享的图片是uiactivityviewcontroller的横向视图。你不能强迫它在风景中显示。