Detect when view controller appears from pop(检测视图控制器何时从弹出窗口出现)
问题描述
我在导航堆栈深处弹出一个视图控制器.是否可以检测视图控制器是从推送还是弹出显示?
I am popping a view controller deep within a navigation stack. Is it possible to detect if the view controller is being shown from a push or a pop?
nav stack:
[A] -> [B] -> [C] -> [D] -> [E]
[E] 弹出到 [B]
[E] pops to [B]
nav stack:
[A] -> [B] // Possible to detect if B appears from a pop?
推荐答案
在视图控制器 B 中,实现 viewWillAppear 或 viewDidAppear.在那里,使用 isMovingToParent 和 isBeingPresented 来查看它在什么条件下出现:
In view controller B, implement either viewWillAppear or viewDidAppear. In there, use isMovingToParent and isBeingPresented to see under what conditions it is appearing:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if !isBeingPresented && !isMovingToParent {
// this view controller is becoming visible because something that was covering it has been dismissed or popped
}
}
以下是人们可能会觉得方便的这些属性的更一般用法:
Below is a more general use of these properties that people may find handy:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isMovingToParent {
// this view controller is becoming visible because it was just push onto a navigation controller or some other container view controller
} else if isBeingPresented {
// this view controller is becoming visible because it is being presented from another view controller
} else if view.window == nil {
// this view controller is becoming visible for the first time as the window's root view controller
} else {
// this view controller is becoming visible because something that was covering it has been dismissed or popped
}
}
这篇关于检测视图控制器何时从弹出窗口出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检测视图控制器何时从弹出窗口出现
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
