ios – 为什么顶部布局指南在我的iMessage扩展中移动

ios – 为什么顶部布局指南在我的iMessage扩展中移动,第1张

概述我有一个iMessage扩展,我在顶部布局指南中遇到了一些问题.我有一个MSMessagesAppViewController来处理表示样式之间的变化.在我的扩展中,我有一个按钮.单击它时,我转换为展开的演示文稿样式,然后以模态方式呈现视图控制器.问题在于:第二个VC中的UI隐藏在顶部导航栏后面.我认为这很奇怪,因为我将约束设置为顶部布局指南.所以我挖掘了我的代码并开始调试顶层布局指南.我注意到在 我有一个iMessage扩展,我在顶部布局指南中遇到了一些问题.我有一个MSMessagesAppVIEwController来处理表示样式之间的变化.在我的扩展中,我有一个按钮.单击它时,我转换为展开的演示文稿样式,然后以模态方式呈现视图控制器.问题在于:第二个VC中的UI隐藏在顶部导航栏后面.我认为这很奇怪,因为我将约束设置为顶部布局指南.所以我挖掘了我的代码并开始调试顶层布局指南.我注意到在转换到扩展的演示文稿样式后,topLayoutGuIDe.length = 86.应该是这样的.但是当我以模态方式呈现第二个视图控制器时,顶部布局指南被重置为0.为什么它不应该是86呢?这是我的代码:

在我的主vIEwController中:

@IBAction func addStickerbuttonpressed(_ sender: AnyObject) {    shouldPerformCreateSegue = true    theSender = sender    requestPresentationStyle(.expanded)}    overrIDe func dIDTransition(to presentationStyle: MSMessagesAppPresentationStyle) {    if presentationStyle == .expanded {        if shouldPerformCreateSegue == true {            shouldPerformCreateSegue = false            performSegue(withIDentifIEr: "CreateStickerSegue",sender: theSender)//here is where I present the new vIEwController        } else {            searchbar.becomeFirstResponder()            searchbar.placeholder = nil            searchbar.showsCancelbutton = true            searchbar.tintcolor = UIcolor.white        }    } else {        searchbar.showsCancelbutton = false    }    print(topLayoutGuIDe.length) //This prints out 86}

在另一个模态呈现的视图控制器中:

overrIDe func vIEwWillAppear(_ animated: Bool) {    super.vIEwWillAppear(animated)    self.vIEw.addConstraint(navbar.topAnchor.constraint(equalTo: topLayoutGuIDe.bottomAnchor))    print(topLayoutGuIDe.length) //This prints out 0}
解决方法 作为一种解决方法,我使用UIPresentationController,它通过topLayoutGuIDe.length点移动模态视图控制器:
class MyVIEwController: MSMessagesAppVIEwController {    private func presentModalVIEwController() {        let imagePicker = UIImagePickerController()        imagePicker.delegate = self        imagePicker.sourceType = .savedPhotosAlbum        imagePicker.modalPresentationStyle = .custom        imagePicker.TransitioningDelegate = self        present(imagePicker,animated: true,completion: nil)    }}// MARK: - UIVIEwControllerTransitioningDelegateextension MyVIEwController: UIVIEwControllerTransitioningDelegate {    func presentationController(forPresented presented: UIVIEwController,presenting: UIVIEwController?,source: UIVIEwController) -> UIPresentationController? {        let vc = PresentationController(presentedVIEwController: presented,presenting: presenting)        // I really don't want to hardcode the value of topLayoutGuIDeLength here,but when the extension is in compact mode,topLayoutGuIDe.length returns 172.0.        vc.topLayoutGuIDeLength = topLayoutGuIDe.length > 100 ? 86.0 : topLayoutGuIDe.length        return vc    }}class PresentationController: UIPresentationController {    var topLayoutGuIDeLength: CGfloat = 0.0    overrIDe var frameOfPresentedVIEwInContainerVIEw: CGRect {        guard let containerVIEw = containerVIEw else {            return super.frameOfPresentedVIEwInContainerVIEw        }        return CGRect(x: 0,y: topLayoutGuIDeLength,wIDth: containerVIEw.bounds.wIDth,height: containerVIEw.bounds.height - topLayoutGuIDeLength)    }}

唯一的问题是当你从紧凑模式调用presentModalVIEwController时,topLayoutGuIDe.length是172.0,原因不明.所以我不得不为这种情况硬编码一个值.

总结

以上是内存溢出为你收集整理的ios – 为什么顶部布局指南在我的iMessage扩展中移动全部内容,希望文章能够帮你解决ios – 为什么顶部布局指南在我的iMessage扩展中移动所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1103597.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存