[英]Swift Unable to present view controller from top to bottom
In my application I have to present the screen from Top to bottom and I have tried below code its giving the same normal presenting style. 在我的应用程序中,我必须从上到下呈现屏幕,我尝试了下面的代码,它给出了相同的正常呈现风格。
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)
For that you need to set subtype
of CATransition
to kCATransitionFromBottom
and for batter animation set animated
to false
with present(_:animated:completion:)
. 对于您需要设置
subtype
的CATransition
到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)
For dismiss set subtype
of CATransition
to kCATransitionFromTop
. 用于将
CATransition
subtype
集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)
Just changed it transition.subtype
to kCATransitionFromBottom
刚刚将
transition.subtype
更改为kCATransitionFromBottom
transition.subtype = kCATransitionFromBottom
transition.subtype = kCATransitionFromBottom
For dismiss the controller. 关闭控制器。
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)
Please find the below GIF representation. 请找到以下GIF表示。
If you are using the .XIB then please find the below code.
如果您使用的是.XIB,请找到以下代码。
For present the controller. 目前是控制器。
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)
For dismiss the controller. 关闭控制器。 It is the same code as above.
它与上面的代码相同。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.