gpt4 book ai didi

ios - 如何像 actionSheet 一样呈现 UIViewController?

转载 作者:可可西里 更新时间:2023-11-01 02:19:06 25 4
gpt4 key购买 nike

我想呈现一个只占据屏幕下半部分的 View ,背景 View 保持可见,没有可能的交互。

就像一个带有 actionSheet 风格的 UIAlertContoller

如何在 Swift 中做到这一点?

最佳答案

将该 View 创建为普通的 UIViewController,为其分配一个标识符,然后像这样实例化它:(尽管将其保留为成员变量,您将需要它)

var controller = self.storyboard!.instantiateViewControllerWithIdentifier("yourIdentifier") as! UIViewController

然后你可以将它添加到你的父 View 中

self.addSubview(controller)

但是要小心定位它,你可以将它整齐地动画到屏幕中间

UIView.animateWithDuration(0.5, animations: {
controller.frame.origin.y = UIScreen.mainScreen().bounds.height/2
})
in

但是初始定位应该是 holding view 的 viewDidLayoutSubviews 方法,比如

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
controller.frame.origin.y = UIScreen.mainScreen().bounds.height
}

因为在 viewDidLoad 中, View 还没有真正正确的框架,它最终会出现在错误的位置

关于ios - 如何像 actionSheet 一样呈现 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32426993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com