我正从具有状态栏的ViewController转到没有。
的状态栏在动画期间,当新的ViewController在顶部滑动时,我看到状态栏快速向上滑动旧的ViewController。
为什么会发生这种情况以及如何解决此问题?
由于以下原因,新的ViewController没有状态栏:
class Coffee:
def __init__(self):
self._price=4.0
def price(self):
return self._price
def __str__(self):
return "Coffee with price "+ str(self._price)
class CoffeeWithMilk:
def __init__(self, coffee):
self.price+=coffee.price+0.5
def price(self):
return self.price
coffee=Coffee()
x=CoffeeWithMilk(coffee)
coffeeWithMilk=CoffeeWithMilk(x)
print(coffeeWithMilk)
演示风格
modalPresentationStyle = “overCurrentContext”
新
使用以下问题创建了一个测试XCode项目: https://github.com/paul301/TestSlideUp
答案 0 :(得分:1)
要使新的ViewController保持在旧状态栏的顶部,您需要创建一个新的UIWindow并手动执行动画。
示例代码:
var window = UIWindow()
//to show new view controller
func showWindow() {
let vc = NewViewController()
self.window.rootViewController = vc
self.window.backgroundColor = UIColor.clear
self.window.windowLevel = UIWindowLevelStatusBar
self.window.frame = CGRect(x: 0, y: UIScreen.main.bounds.height, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
self.window.isHidden = false
UIView.animate(withDuration: 0.5) {
self.window.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
}
}