Animating the presenting view in a UIPresentationController

后端 未结 2 1187
遥遥无期
遥遥无期 2021-01-03 17:05

For some context, I recommend reading this:

Very relevant question: "From View Controller" disappears using UIViewControllerContextTransitioning Very relev

2条回答
  •  半阙折子戏
    2021-01-03 17:57

    I'm adding another answer, as my response is too long to fit in a comment.

    First of all the viewForKey is available in iOS8, so unless you are targeting iOS8 only (why?) you should not use it, or use it after checking that the UIViewControllerContextTransitioning responds to that selector and use the viewControllerForKey for iOS7.

    With that being said, it seems to me that this is a bug and I explain my self:

    If you look at the UIPresentationController header file, you will see that it says

    // Indicate whether the view controller's view we are transitioning from will be removed from the window in the end of the
    // presentation transition
    // (Default: YES)
    - (BOOL)shouldRemovePresentersView;
    

    So as you see the default is YES, so this should only overriden when you specifically want to say NO. However, you are right, without this being set explicitly to YES, the viewForKey for the UITransitionContextFromViewControllerKey remains nil.

    I think you should fill in a bug report for this and for now use the viewControllerForKey which is fine to be used (nothing wrong with this) as it's not deprecated and works in both OS versions without a problem.

    And the reason this is most likely a bug is that the viewForKey should return a view for theUITransitionContextFromViewControllerKey when the shouldRemovePresentersView is explicitly set to NO and not YES.

    My 2 cents

提交回复
热议问题