大佬教程收集整理的这篇文章主要介绍了ios – 为什么顶部布局指南在我的iMessage扩展中移动,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的主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 }
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: - UIViewControllerTransitioningDelegate extension 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扩展中移动所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。