gpt4 book ai didi

ios - 当界面方向颠倒时呈现 View Controller

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:07 24 4
gpt4 key购买 nike

我的 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 (正如它应该的那样)。

presenting view controller B

当关闭 View Controller B 时,它会立即翻转并移出 View 到顶部(而不是它来自的方向,如第二个屏幕截图所示)。

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self dismissModalViewControllerAnimated:YES];
}

dismissing view controller B

这是 iOS 中的错误还是我如何避免这种奇怪的行为?

(我只需要与正常纵向模式相同的标准动画来呈现 View Controller - 没有这些翻转。)

最佳答案

我猜 MFMailComposeViewController 不支持颠倒的界面方向,这就是为什么它可以被解释为错误。 但是 Apple 建议不要为 iPhone 应用程序使用颠倒的界面方向。其主要原因可以通过这样的例子来解释:

  1. 用户打开应用程序并将 iPhone 旋转到上下颠倒的方向。
  2. 这时有人调用它。
  3. 用户试图接听电话,但忘记将手机旋转到默认纵向。
  4. 因此 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 application approving center 重写类别中的现有方法。

关于ios - 当界面方向颠倒时呈现 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23249252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com