我的iPhone应用程序支持颠倒的界面方向: 当用户将手机倒置(使主页按钮位于顶部)时,整个用户界面将垂直翻转。
但是,当尝试从我的 View Controller A 呈现某些 View Controller B 时,会出现问题(在本示例中,我呈现标准邮件编辑器 View Controller ):
- (IBAction)buttonTapped:(id)sender {
MFMailComposeViewController *mailVC = [MFMailComposeViewController new];
mailVC.mailComposeDelegate = self;
[self presentViewController:mailVC animated:YES completion:nil];
}
当此方法被触发时,发生的第一件事是(蓝色) View Controller A立即垂直翻转,无论出于何种原因(如第一个屏幕截图所示)→为什么?
接下来,呈现的 View Controller B从底部移动到 View 中(正如它应该的那样)。
当关闭 View Controller B时,它会立即翻转,并从 View 移出到顶部(而不是像第二个屏幕截图中所示的方向一样)。
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self dismissModalViewControllerAnimated:YES];
}
这是 iOS 中的错误吗?我该如何避免这种奇怪的行为?
(我只想要与正常纵向模式相同的标准动画来呈现 View Controller - 没有这些翻转。)
最佳答案
我猜 MFMailComposeViewController
不支持颠倒的界面方向,这就是它可以被解释为错误的原因。 但是 Apple 建议不要对 iPhone 应用程序使用颠倒的界面方向。其主要原因可以用这样的例子来解释:
- 用户打开应用程序并将 iPhone 旋转至颠倒方向。
- 此时有人调用他。
- 用户尝试接听电话,却忘记将手机旋转至默认纵向。
- 因此,iPhone 的麦克风靠近用户的耳朵,扬声器靠近用户的嘴。
这不是用户友好的体验。
我会考虑在您的网站上是否使用颠倒方向。
但是,如果需要使用颠倒的界面方向,那么您可以使用这样的技巧:
创建 MFMailComposeViewController
类别并重写方法 supportedInterfaceOrientations
以允许支持必要的方向,并将其导入到创建 MFMailComposeViewController
的类中:
// MFMailComposeViewController+Orientation.h file
#import <MessageUI/MessageUI.h>
@interface MFMailComposeViewController (Orientation)
@end
// MFMailComposeViewController+Orientation.m file
#import "MFMailComposeViewController+Orientation.h"
@implementation MFMailComposeViewController (Orientation)
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
@end
注意:我不确定这个技巧是否会被抛出Apple应用程序审批中心,因为它会覆盖类别中现有的方法。
关于ios - 当界面方向颠倒时呈现 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23249252/