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

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

概述在下面的委托函数中我试图做,但没有得到理想的结果 override func didUpdateFocusInContext(context: UIFocusUpdateContext,withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) { if (context.nextFocusedView == sel 在下面的委托函数中我试图做,但没有得到理想的结果

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(),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().CGcoloroverrIDe 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全部内容,希望文章能够帮你解决swift – 我们可以使用UIButton停止或删除焦点上的动画效果,并提供其他边框效果tvOS所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1003887.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存