Why is the top layout guide moving in my iMessage extension

前端 未结 3 881
挽巷
挽巷 2021-02-09 00:42

I have an iMessage extension and I\'m having some issues with the top layout guide. I have an MSMessagesAppViewController that handles changes between presentation

3条回答
  •  佛祖请我去吃肉
    2021-02-09 01:26

    I used a slightly varied version of Andrey's

    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
            )
        }
    }
    
    extension MyViewController: UIViewControllerTransitioningDelegate {
        func presentationController(
             forPresented presented: UIViewController,
             presenting: UIViewController?,
             source: UIViewController
        ) -> UIPresentationController? {
             let vc = PresentationController(
                 presentedViewController: presented,
                 presenting: presenting
             )
             vc.framePresented = modalBoundaries.frame
             return vc
        }
    }
    
    class PresentationController: UIPresentationController {
         var framePresented = CGRect.zero
         override var frameOfPresentedViewInContainerView: CGRect {
             return framePresented
        }
    }
    

    modalBoundaries being a dummy UIView constrained (via XIB in my case) to respect any TopLayoutGuide length.

提交回复
热议问题