我有一个适用于 tvOS 的小型测试应用程序 - 带有两个按钮的白色背景。这些按钮是标准的 UIButton
,除了设置标题文本和将 titleColor
设置为黑色外没有任何自定义。
我的 UIButton
在获得焦点时不会收到阴影(或任何动画)。如果我将它们替换为 UITextField
,它们将获得预期的默认投影和动画。我可以确认按钮确实通过添加目标并在被选中时打印到控制台来获得焦点。
知道发生了什么事吗? Apple's documentation , this article和 this answer所有建议 UIButton
应该像其他可聚焦元素一样自动接收默认焦点动画。这是错误还是我遗漏了什么?
相关代码:
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.whiteColor()
let button = UIButton()
button.setTitle("Button", forState: .Normal)
button.setTitleColor(UIColor.blackColor(), forState: .Normal)
button.frame = CGRectMake(500, 500, 300, 100)
view.addSubview(button)
let button2 = UIButton()
button2.setTitle("Button2", forState: .Normal)
button2.setTitleColor(UIColor.blackColor(), forState: .Normal)
button2.frame = CGRectMake(900, 500, 300, 100)
view.addSubview(button2)
}
编辑:这仅在以编程方式添加 UIButton
时发生 - 如果我在 Interface Builder 中添加它们,它们将正常运行。
最佳答案
调用 UIButton()
初始化程序将为您提供一个“自定义”按钮,而您真正想要的是一个“系统”按钮,如下所示:
let button = UIButton(type: .System)
自定义按钮根本没有任何内置外观,而系统按钮有。
关于objective-c - tvOS - UIButton 在聚焦时不动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34801541/