关闭UIActivityViewController后的正确方向 [英] Correct orientation after UIActivityViewController is dismissed

查看:148
本文介绍了关闭UIActivityViewController后的正确方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从控制器中显示UIActivityViewController.我遇到了轮换问题.选择一些数据共享选项后,假设邮件",将显示邮件撰写视图控制器.但是,如果我旋转设备并随后关闭邮件控制器,则我的VC不会旋转到当前方向.我试图按照以下步骤为UIActivityViewController设置完成处理程序:

I am presenting UIActivityViewController from my controller. I've encountered issues with rotations. After some data sharing option is chosen, let's say "Mail", mail compose view controller is presented. But if I rotate the device and dismiss the mail controller afterwards, my VC is not rotated to the current orientation. I've tried to set up the completion handler for UIActivityViewController as following:

1)

[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed){
            [UIViewController attemptRotationToDeviceOrientation];
        }];

2)

[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed){
        UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
        [self layoutForInterfaceOrientation:currentOrientation];
    }];

第一个解决方案根本没有帮助.第二种解决方案使导航栏保持不变(高度相差12点).

The first solution did not help at all. The second solution left the navigation bar unrotated (12 points difference in height).

请告知如何处理这种情况.

Please advise how to handle this situation.

推荐答案

我已经解决了该问题.首先,我应该说,在关闭MailComposeVC之后,无论当前设备的方向及其状态如何,在显示邮件之前,我的VC总是旋转为纵向... 屏幕上显示MailComposeVC时,在自动旋转过程中调用的唯一VC方法是viewWillLayoutSubviews/viewDidLayoutSubviews. (未调用willAnimateRotationToInterfaceOrientation!) 因此,我重置了导航栏以恢复其高度,并在我的VC不可见的情况下调用了自定义布局方法,如下所示:

I've resolved the issue. First of all, I should say that my VC is always rotated to portrait after MailComposeVC is dismissed regardless of the current device orientation and its state before showing a mail... And the only VC method that gets called during auto rotation when MailComposeVC is on screen is viewWillLayoutSubviews/viewDidLayoutSubviews. (willAnimateRotationToInterfaceOrientation is not called!) So, I reset the navigation bar to recover its height and call my custom layout method if my VC is invisible, like that:

(void) viewDidLayoutSubviews {
    // HACK: forcing the bars to refresh themselves - this helps to get the shorter version when switching to landscape and the taller one when going back!!!
    if (amIhidden) { 
        [self.navigationController setNavigationBarHidden:YES animated:NO];
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
        [self layoutForInterfaceOrientation:currentOrientation];
    }
}

呈现MailComposeViewController时会设置

amIhidden BOOL,如下所示:

amIhidden BOOL is set when presenting MailComposeViewController, as following:

UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
                                                        initWithActivityItems:@[self]
                                                        applicationActivities:nil];
amIhidden = YES;
[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed){
        amIhidden = NO;
}];
[self presentViewController:activityViewController animated:YES completion:nil];

希望,我的解决方案将对其他人有所帮助!

Hope, my solution will help to somebody else!

这篇关于关闭UIActivityViewController后的正确方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆