swift – 我们可以使用UIButton停止或删除焦点上的动画效果,并提
发布时间:2020-12-14 04:33:35 所属栏目:百科 来源:网络整理
导读:在下面的委托函数中我试图做,但没有得到理想的结果 override func didUpdateFocusInContext(context: UIFocusUpdateContext,withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) { if (context.nextFocusedView == self) { coordinator.add
在下面的委托函数中我试图做,但没有得到理想的结果
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().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) } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- PostgreSQL不同的表使用不同的自增序列
- WebView整合,Hybrid Apps起始
- 【Android 开发】:数据存储之 SQLite 数据库操作(三)
- ruby-on-rails – OAuth2和Omniauth之间的区别
- NAND FLASH 和 NOR FLASH开机启动
- objective-c – Facebook iOS SDK:检索用户的电话号码和国
- JSONObject, JSONArray来构建json文本
- ruby-on-rails – ActiveRecord :: HasManyThroughOrderErr
- logback.xml 配置总结
- Swift在引用类属性时是否正在制作数据的副本?