Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从MSMessageAppViewController正确呈现UIAlertController_Ios_Objective C_Msmessage - Fatal编程技术网

Ios 从MSMessageAppViewController正确呈现UIAlertController

Ios 从MSMessageAppViewController正确呈现UIAlertController,ios,objective-c,msmessage,Ios,Objective C,Msmessage,我正在尝试找出如何在我的iMessage应用程序扩展中显示样式为UIAlertControllerStyleActionSheet的UIAlertController 问题是,调用时显示的操作表显示在本机iMessage文本字段下方: [self.view.window.rootViewController presentViewController:actionSheetController动画:是完成:NULL] 我该如何着手解决这个问题 代码: 这里有一个解决方法。也许可以添加一点动画使其

我正在尝试找出如何在我的iMessage应用程序扩展中显示样式为
UIAlertControllerStyleActionSheet
UIAlertController

问题是,调用时显示的操作表显示在本机iMessage文本字段下方:

[self.view.window.rootViewController presentViewController:actionSheetController动画:是完成:NULL]

我该如何着手解决这个问题

代码:


这里有一个解决方法。也许可以添加一点动画使其平滑

[self.view.window.rootViewController presentViewController:actionSheetController animated:YES completion:^{
    actionSheetController.view.frame = CGRectOffset(actionSheetController.view.frame, 0, -40);
}];
根据,您可以通过以下方式请求全屏演示:

[self requestPresentationStyle:MSMessagesAppPresentationStyleExpanded];
在代码之前:

[self.view.window.rootViewController presentViewController:actionSheetController animated:YES completion:NULL];
另一个解决方法:

actionSheetController.view.transform = CGAffineTransform(translationX: 0, y: -40)    
[self.view.window.rootViewController presentViewController:actionSheetController animated:YES completion:NULL];

不要硬编码操作表的y位置

当苹果改变iMessage dock的高度时,这可能会在以后的iOS主要更新中导致ui问题。而是使用
safeAreaInsets.bottom
值,以找出dock隐藏视图的值

以下是我们正在使用的解决方案:

    let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

    actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (_) in
        actionSheet.dismiss(animated: true, completion: nil)
    }))

    // Adding further actions...

    present(actionSheet, animated: true) {
        UIView.animate(withDuration: 0.2, animations: {
            actionSheet.view.frame = CGRect(x: actionSheet.view.frame.minX,
                                            y: actionSheet.view.frame.minY - self.view.safeAreaInsets.bottom,
                                            width: actionSheet.view.frame.width,
                                            height: actionSheet.view.frame.height)
        })
    }
细节:操作表被iMessage dock隐藏,因为在其上显示操作表的视图控制器视图绑定到视图的底部,而不是iMessage dock的顶部。例如,在向其他视图及其子视图添加约束时,必须考虑这种情况


更新:

为了避免上面的动画,只需使用以下代码。在我看来,看了一段时间动画后,我确实变得很烦人

extension UIAlertController {
    open override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        guard let viewController = presentingViewController else { return }
        view.transform = .identity
        view.transform = .init(translationX: 0.0, y: - viewController.view.safeAreaInsets.bottom)
    }
}

您能否在
MSMessageAppViewController
上演示
UIAlertController
?这是一个已知问题。iOS 10/10.1发行说明中写道:“当UIAlertController对象出现在消息扩展中时,它会被扩展的底部栏截断。”打开错误报告,告诉Apple这对您很重要。iMessage文本字段属于某个窗口,该窗口高于您的
self.view.window
,但低于状态栏。您可能希望尝试使用
windowLevel=UIWindowLevelStatusBar
添加一个新的
UIWindow
,并显示来自该窗口的警报window@VladFedoseev刚刚试过这个,但没用
UIWindow*window=UIWindow.new;window.rootViewController=self;window.windowLevel=UIWindowLevelStatusBar;[WindowMakeKeyandVisible];[window.rootViewController presentViewController:alertController动画:是完成:NULL]我可以用AlertStyle演示UIAlertController。但是,我在解雇时偶尔会遇到崩溃,因此我建议创建一个UIView并将其作为子视图添加到MSMessageAppViewControllert这是有问题的,因为任何布局过程都会将警报控制器的视图移动到其原始位置。@LeoNatan如果需要,您可以使用KVO center属性并重新调整框架。即使展开,警报控制器仍会显示在输入栏下。此外,您还可以使用
UIAlertControllerStyleAlert
作为
UIAlertController首选样式:
。。。警报总是出现在屏幕中间(甚至在iPad上)…最后我自己用了。。。
extension UIAlertController {
    open override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        guard let viewController = presentingViewController else { return }
        view.transform = .identity
        view.transform = .init(translationX: 0.0, y: - viewController.view.safeAreaInsets.bottom)
    }
}