- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个自定义的 UIStoryboardSegue,可以在 iOS12.* 中按需要工作。
目标 View Controller 之一是 UITabbarController:对于每个选项卡,我都有一个嵌入在导航 Controller 中的 Controller 。
不幸的是,对于 iOS13.*,这不能很好地工作: View Controller 生命周期被破坏,并且不再调用 viewXXXAppear() 和 willTransition() 方法。
看起来 makeKeyAndVisible() 没有效果?!
在底部查看屏幕 UI 在没有调用 viewWillAppear() 的情况下是如何困惑的。
一个可怕的临时解决方法
我不得不拉我的头发,但是,我找到了一个公开的修复程序(我必须即时添加导航 Controller )。
这弄乱了 vc 层次结构:你有更好的解决方案吗?
public class AladdinReplaceRootViewControllerSegue: UIStoryboardSegue {
override public func perform() {
guard let window = UIApplication.shared.delegate?.window as? UIWindow,
let sourceView = source.view,
let destinationView = destination.view else {
super.perform()
return
}
let screenWidth = UIScreen.main.bounds.size.width
let screenHeight = UIScreen.main.bounds.size.height
destinationView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)
window.insertSubview(destinationView, aboveSubview: sourceView)
// **My fix**
if #available(iOS 13,*) {
// I introduced an invisible navigation controller starting in iOS13 otherwise, my controller attached to the tabbar thru a navigation, dont work correctly, no viewXAppearis called.
let navigationController = UINavigationController.init(rootViewController: self.destination)
navigationController.isNavigationBarHidden = true
window.rootViewController = navigationController
}
else {
window.rootViewController = self.destination
}
window.makeKeyAndVisible()
}
}
最佳答案
感谢 Unbalanced calls to begin/end appearance transitions with custom segue,我找到了解决方案
这里发生的事情是目标 View Controller 的创建和附加发生了两次,第一个发生得太快了。
所以你需要做的是:
public class AladdinReplaceRootViewControllerSegue: UIStoryboardSegue {
override public func perform() {
guard let window = UIApplication.shared.delegate?.window as? UIWindow,
let sourceView = source.view,
let destinationView = destination.view else {
super.perform()
return
}
let screenWidth = UIScreen.main.bounds.size.width
let screenHeight = UIScreen.main.bounds.size.height
let mock = createMockView(view: desination.view)
window.insertSubview(mock, aboveSubview: sourceView)
//DO SOME ANIMATION HERE< MIGHT NEED TO DO mock.alpha = 0
//after the animation is done:
window.rootViewController = self.destination
mock.removeFromSuperview()
}
func createMockView(view: UIView) -> UIImageView {
UIGraphicsBeginImageContextWithOptions(view.frame.size, true, UIScreen.main.scale)
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return UIImageView(image: image)
}
}
关于UIViewController 生命周期断了 iOS13,makeKeyAndVisible() 好像不能操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58360026/
在引用此文档pressable docs之后,我将Pressable用于按钮 现在,我想向按钮添加波纹效果,但是它无法正常工作。 Button 如果按钮具有
在 C# 中,我想制作“智能”枚举,这在 Java 中是可能的,其中有更多信息附加到枚举值,而不仅仅是底层 int。我偶然发现了一个创建类(而不是枚举)的方案,如以下简单示例所示: public se
当执行 git stash 时,会创建 2 个提交。一个被 stash ref 引用并且有 2 个父提交。一位 parent 是我们 stash 地点的索引。另一方拥有我们 stash 的实际内容。
我是一名优秀的程序员,十分优秀!