在下面的代码中,UIKeyboard 比视图大。
问题:如何使键盘与视图大小相同?
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController, UITextFieldDelegate {
override func loadView() {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
view.backgroundColor = .white
let label = UITextField()
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
label.text = "Hello World!"
label.textColor = .black
label.addTarget(self, action: #selector(myTargetFunction), for: .touchDown)
view.addSubview(label)
self.view = view
}
@objc func myTargetFunction() {
print("It works!")
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
到目前为止,我发现的唯一“解决方案”是将preferredContentSize
UIViewController 的UIScreen.main
设置为当前 Xcode Playground 环境的大小:
let vc = MyViewController()
vc.preferredContentSize = UIScreen.main.bounds.size
PlaygroundPage.current.liveView = vc
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句