我的 iPhone 应用程序设计为仅支持纵向,除了一个显示照片的 View Controller 外,还支持横向模式。
总的来说,我的项目支持所有方向,但每个 View Controller (照片 View Controller 除外)都实现了该方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
问题:
在我的一个(仅纵向) View Controller 中,我使用 UIActivityViewController
让用户选择通过电子邮件或 SMS 共享内容。
当用户选择电子邮件选项时,它会自动显示 ios native 电子邮件 View Controller 。
如果用户现在将设备的方向更改为横向,电子邮件 View Controller 也会更改为横向,现在如果用户点击取消/发送按钮,电子邮件 Controller 将被关闭,现在我的所有应用程序都是横向的!
有没有办法强制 eamil View Controller 仅处于纵向模式?
我知道我可以创建自己的电子邮件 View Controller 和子类 UIActivity
来显示它,但是 UIActivityViewController
在显示时不会显示默认电子邮件图标,并且我真的很喜欢它来显示它,而不是我将提供的其他一些(必须是灰色的)图标。
最佳答案
您应该制作另一个 uinavigationcontroller 并从那里呈现 uiactivityviewcontroller。 在此代码中,_image 是您要共享的 UIImage。 BlankViewController 只是占位符 View Controller ,您可以在 IB 中创建它,您还可以设置它的 View 背景颜色以清除并执行您想要执行的任何外观更改。
__weak CurrentViewController *weakSelf = self ;
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[_image] applicationActivities:nil] ;
UIViewController *viewC = [[UIViewController alloc] initWithNibName:@"BlankViewController" bundle:nil] ;
UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:viewC] ;
activityViewController.completionHandler = ^(NSString *activityType, BOOL completed)
{
[weakSelf dismissViewControllerAnimated:NO completion: ^ {
; // Your completion handler
}] ;
};
[self presentViewController:navC animated:NO completion: ^ {
[navC presentViewController:activityViewController animated:YES completion: ^ {
;
}] ;
}];
关于iphone - Objective c - UIActivityViewController 方向模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14978432/