gpt4 book ai didi

swift - 我们可以使用 UIButton 停止或删除焦点上的动画效果并提供其他边框效果 tvOS

转载 作者:搜寻专家 更新时间:2023-10-31 08:33:10 25 4
gpt4 key购买 nike

在下面的委托(delegate)函数中,我尝试执行但没有得到想要的结果

override func didUpdateFocusInContext(context: UIFocusUpdateContext,withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
if (context.nextFocusedView == self) {
coordinator.addCoordinatedAnimations({ () -> Void in
self.animationDidStop(CAAnimation(), finished: true)
}, completion: { () -> Void in

})

}
else {
// handle unfocused appearance changes

coordinator.addCoordinatedAnimations({ () -> Void in
self.animationDidStop(CAAnimation(), finished: true)
}, completion: { () -> Void in

})
}
context.nextFocusedView?.layer.shadowOffset = CGSizeZero
context.nextFocusedView?.layer.shadowOpacity = 0.9;
context.nextFocusedView?.layer.shadowRadius = 0;
context.nextFocusedView?.layer.shadowColor= UIColor.orangeColor().CGColor
context.previouslyFocusedView?.layer.shadowOpacity = 0;
}

最佳答案

首先,您必须将按钮类型设置为自定义类型。通过自定义类型,您将不再获得系统动画,因此您必须自己制作所有动画。

然后你可以在 UIViewController 中实现 didUpdateFocusInContext 方法,或者你可以创建你自己的 UIButton 子类,如果有更多的按钮类型屏幕。

这是我在 UIButton 子类中使用的代码。这将提供按钮放大以及焦点上的红色边框,并在焦点丢失时进入正常状态。

let scale = 1.1    
layer.borderColor = UIColor.redColor().CGColor

override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {

if context.nextFocusedView == self {
coordinator.addCoordinatedAnimations({ () -> Void in

self.transform = CGAffineTransformMakeScale(scale, scale)
self.layer.borderWidth = 2

}, completion: nil)
}
else {
coordinator.addCoordinatedAnimations({ () -> Void in

self.transform = CGAffineTransformIdentity
self.layer.borderWidth = 0

}, completion: nil)
}
}

关于swift - 我们可以使用 UIButton 停止或删除焦点上的动画效果并提供其他边框效果 tvOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33372227/

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