我试图以编程方式触发tvOS中的按钮上的UIPress,这样我就可以获得用户点击按钮时收到的相同动画。我试过这个:
// This is Swift 3 but a Swift 2 answer or even Objective-C is fine
button.sendActions(for: UIControlEvents.touchUpInside)
该命令执行按钮的单击,但不执行按下的聚焦按钮的动画。
答案 0 :(得分:2)
您可以为UIButton
设置动画。您也应该使用.PrimaryActionTriggered
代替.touchUpInside
。例如:
let animationDuration = 0.2
let focusedScaleFactor: CGFloat = 1.2
UIView.animateWithDuration(animationDuration, animations: {
button.transform = CGAffineTransformMakeScale(focusedScaleFactor, focusedScaleFactor)
}) { (finished) in
UIView.animateWithDuration(animationDuration, animations: {
button.transform = CGAffineTransformIdentity
}) { (finished) in
button.sendActions(for: .PrimaryActionTriggered)
}
}