Swift 无法从上到下呈现视图控制器
Swift Unable to present view controller from top to bottom
在我的应用程序中,我必须从上到下呈现屏幕,并且我尝试使用下面的代码提供相同的正常呈现样式。
let screen = self.storyboard?.instantiateViewController(withIdentifier: "Screen1p5") as? Screen1p5
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromTop
view.window!.layer.add(transition, forKey: kCATransition)
self.present(screen!, animated: true, completion: nil)
为此,您需要将 CATransition
的 subtype
设置为 kCATransitionFromBottom
,将连击动画设置为 animated
至 false
,并使用 present(_:animated:completion:)
.
let screen = self.storyboard?.instantiateViewController(withIdentifier: "Screen1p5") as? Screen1p5
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromBottom
view.window!.layer.add(transition, forKey: kCATransition)
self.present(screen!, animated: false, completion: nil)
要解散,将 CATransition
的 subtype
设置为 kCATransitionFromTop
。
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromTop
view.window!.layer.add(transition, forKey: kCATransition)
self.dismiss(animated: false)
刚把它transition.subtype
改成了kCATransitionFromBottom
transition.subtype = kCATransitionFromBottom
解散控制器。
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromTop
view.window!.layer.add(transition, forKey: kCATransition)
self.dismiss(animated: true, completion: nil)
请找到下面的 GIF 表示。
If you are using the .XIB then please find the below code.
为目前控制器。
let newController = NewViewController(nibName: "NewView", bundle: nil)
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromBottom
view.window!.layer.add(transition, forKey: kCATransition)
self.present(newController, animated: true, completion: nil)
用于解雇控制器。和上面的代码是一样的。
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromTop
view.window!.layer.add(transition, forKey: kCATransition)
self.dismiss(animated: true, completion: nil)
在我的应用程序中,我必须从上到下呈现屏幕,并且我尝试使用下面的代码提供相同的正常呈现样式。
let screen = self.storyboard?.instantiateViewController(withIdentifier: "Screen1p5") as? Screen1p5
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromTop
view.window!.layer.add(transition, forKey: kCATransition)
self.present(screen!, animated: true, completion: nil)
为此,您需要将 CATransition
的 subtype
设置为 kCATransitionFromBottom
,将连击动画设置为 animated
至 false
,并使用 present(_:animated:completion:)
.
let screen = self.storyboard?.instantiateViewController(withIdentifier: "Screen1p5") as? Screen1p5
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromBottom
view.window!.layer.add(transition, forKey: kCATransition)
self.present(screen!, animated: false, completion: nil)
要解散,将 CATransition
的 subtype
设置为 kCATransitionFromTop
。
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromTop
view.window!.layer.add(transition, forKey: kCATransition)
self.dismiss(animated: false)
刚把它transition.subtype
改成了kCATransitionFromBottom
transition.subtype = kCATransitionFromBottom
解散控制器。
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromTop
view.window!.layer.add(transition, forKey: kCATransition)
self.dismiss(animated: true, completion: nil)
请找到下面的 GIF 表示。
If you are using the .XIB then please find the below code.
为目前控制器。
let newController = NewViewController(nibName: "NewView", bundle: nil)
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromBottom
view.window!.layer.add(transition, forKey: kCATransition)
self.present(newController, animated: true, completion: nil)
用于解雇控制器。和上面的代码是一样的。
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromTop
view.window!.layer.add(transition, forKey: kCATransition)
self.dismiss(animated: true, completion: nil)