gpt4 book ai didi

keyboard - swift playground UITextField 产生太大的键盘

转载 作者:行者123 更新时间:2023-12-04 03:56:23 25 4
gpt4 key购买 nike

Swift 在 Mac OS 上的操场上。当用户在 UItextfield 中单击时,会生成一个键盘,但它与 View 相比非常大,并且只有前几个键可用。

最小的例子:

import UIKit
import PlaygroundSupport

class TesterViewController : UIViewController {
var testTextField : UITextField!
override func loadView() {
let view = UIView()
view.backgroundColor = .white

testTextField = UITextField()
testTextField.borderStyle = .roundedRect
testTextField.text = ""
view.addSubview(testTextField)
testTextField.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
testTextField.topAnchor.constraint(equalTo: view.topAnchor, constant: 20),
testTextField.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
])

self.view = view
}
}
PlaygroundPage.current.liveView = TesterViewController()

截屏
enter image description here

最佳答案

我面临同样的问题。似乎 Playground 的硬编码屏幕尺寸为 768x1024(在 Playground 中运行 UIScreen.main.bounds)并根据此尺寸显示键盘,而与实时 View 的实际尺寸无关。

我想出的最佳解决方法是增加 View Controller 的大小,使其与键盘匹配:

let vc = TesterViewController()
vc.preferredContentSize = vc.view.frame.size // or a custom CGSize
PlaygroundPage.current.liveView = vc

当然,这会使 View 比您希望的要大,所以我只在我真的必须访问屏幕键盘进行测试时才使用这种解决方法。

关于keyboard - swift playground UITextField 产生太大的键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46867712/

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