
在我的主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扩展中移动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)