isBeingPresented 值不一致 [英] isBeingPresented value is inconsistent
问题描述
我以模态方式呈现了一个带有 ViewController 的 NavigationController.
I present a NavigationController with a ViewController in it modally.
在 ViewController 中,我可以看到 self.navigationController.isBeingPresented
为真.
In the ViewController I can see that self.navigationController.isBeingPresented
is true.
但是如果我现在在模态呈现的 NavigationController 上推送一个新的 ViewController 并弹回原始的 ViewController,那么检查 isBeingPresented
的相同调用将返回 false.
But if I now push a new ViewController on the modally presented NavigationController and pop back to the original ViewController the same call to check isBeingPresented
returns false.
文档很少,但除了可能是错误之外,我无法真正解释这种不一致之处?
Documentation is sparse but I can't really explain this inconsistency other than that it may be a bug?
推荐答案
这就是预期的行为.isBeingPresented
仅在给定的 viewController
当前被呈现时才为真(docs):
That's the intended behavior.
isBeingPresented
is true only when the given viewController
is currently being presented (docs):
一个布尔值,指示是否正在呈现视图控制器.
A Boolean value indicating whether the view controller is being presented.
而不是当它已经呈现时.它在呈现过程中设置为 true - 从导航到该视图控制器开始到完全呈现视图控制器的那一刻,并且所有生命周期事件都发生了(呈现动画完成,viewWillAppear
/viewDidAppear
回调被调用等).在那一刻之后,视图控制器被呈现,但不是正在呈现,因此isBeingPresented
将不设置为真了.
and not when it is already presented. It is set to true during the presentation process - from the point when navigation to that view controller starts until the moment when the view controller is fully presented, and all the lifecycle events happened (presentation animations finished, viewWillAppear
/viewDidAppear
callbacks were called, etc.). After that moment, the view controller is presented, but not is being presented, thus the isBeingPresented
will not be set to true anymore.
self.navigationController
最初是呈现的(通过模态呈现),从中弹出一个视图控制器不会触发呈现.在呈现 UINavigationController
之后,它会在其上推送和弹出视图控制器的整个过程中呈现.您将不得不 dismiss
navigationController
,然后再次显示它以使 isBeingPresented
为 true
- 因为只有在模态呈现期间,它正在呈现.
The self.navigationController
was presented at first (by modal presentation), popping a view controller from it does not trigger a presentation. After presenting a UINavigationController
, it is presented whole time during pushing and popping view controllers on it. You would have to dismiss
the navigationController
, and then present it again for the isBeingPresented
to be true
- because only during modal presentation it is being presented.
这篇关于isBeingPresented 值不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!