- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
UIButton
可以配置为在启用或禁用按钮时使用不同的样式、标题等,例如与 UIButton.setTitle(String, forState:UIControlState)
.
ReactiveCocoa
让我连接一个ReactiveSwift.Action
到按钮的 reactive.pressed
属性(property),如果Action
禁用按钮将显示禁用样式:这太棒了!
但是一个ReactiveSwift.Action
当它有 SignalProducer
时也被禁用进行中。这种锁定对于附加到缓慢操作(例如网络请求)的 UI 元素很有用,但当操作快速但不是即时时会产生不良的视觉闪烁。
一个简单的解决方法是不使用内置 UIButton
禁用样式:相反,我们可以公开一个 Property<Bool>
某处并同时使用它来启用/禁用 Action
并明确更改按钮的样式。然而,这有点笨拙和尴尬,所以我的问题是:是否有一种“干净”的方式来组合 UIButton
内置禁用样式,通过显式禁用 Action
来禁用按钮里面UIButton.reactive.pressed
, 没有在操作进行时显示禁用样式?
最佳答案
我们最终使用了 application
reserved area in the UIControlState
bitset明确编码:
extension UIControlState {
public static var myActionIsExecuting = UIControlState(rawValue: 1 << 16)
}
public class ReactiveAwareStylingButton: UIButton {
override public var state: UIControlState {
return [super.state, customState]
}
var customState: UIControlState {
if reactive.pressed?.isExecuting.value == true {
return [.myActionIsExecuting]
}
return []
}
}
这样我们就可以使用标准的依赖于状态的样式选项,例如
button.setTitleColor(normalColor, for: .normal)
button.setTitleColor(normalColor, for: [.disabled, .myActionIsExecuting])
button.setTitleColor(disabledColor, for: .disabled)
如果需要,我们仍然可以选择在操作执行时使用禁用的样式(这可能适用于缓慢的操作,例如网络请求),只需忽略 .myActionIsExecuting
状态.
如果应用此技术,请注意编译器会乐于允许您犯语义错误:您可以将上述样式应用于 UIButton
实例,该实例不是自定义子类ReactiveAwareStylingButton
,永远不会进入状态.myActionIsExecuting
。您应该防止出现此错误,例如通过仅在采用 ReactiveAwareStylingButton
参数的函数中应用样式。
关于ios - ReactiveSwift/ReactiveCocoa : How to use UIButton disabled styling but not when Action is in progress?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50983762/
这对我来说似乎很简单,但我找不到合适的属性。出于错误报告的目的,我想知道我所在的内部过程的名称。 这是最简单的示例: 运行测试。 程序测试。 /* 如何在此处显示过程名称“test”? */ 结束程序
虽然这不是我的主要职责,但我从事 Progress 4GL 已经 8 年了。我更多地使用 C++ 和 Java。当用其他语言编程时,建议声明接近用法。然而,对于 4GL,我看到人们将声明放在文件的顶部
我注意到 Progress 4gl 中的 IF 语句有一个非常奇怪的行为。 我定义了一个格式为“999”的整数,它告诉它有 3 位数字,然后我分配一个小于 100 的值(例如 12),然后当我显示它时
我有下面的代码片段(如之前的 Stack Overflow 回答... Deleting all special characters from a string in progress 4GL 中所
如何将数字和字符串添加到 Progress4GL 上的字符变量中 如下所示(这只是一个展示想法的例子)。 a = 'Code' b = 1 c = a+b 所以c的值为“Code1” 我怎样才能在pr
我有一个缓冲区,其中混合了数据、数字和字符字段。我正在显示字段的值,但由于某种原因,日期字段返回“?”当我尝试将它们添加到字符串时。 我还明白吗?即使我这样做 ASSIGN lvString = lv
有没有办法用特定字符格式化正在进行的字符串? 一个示例显示了前 6 个数字为 x 的 SSN。我已尝试使用 String 函数,但它不支持以格式发送的字母 x。 SSNString = '333224
我正在寻找好的文献来学习 Progress 4GL。这是一个与工作空间相关的项目,无法获得培训资金。我试过文档,但它不准确且相当困惑。 我将不得不在 OE 10.1B 上的 ChUI 中完成大部分工作
我如何计算总数?表中的记录?我想显示数据库中的所有表名以及编号。每个表中的记录数 最佳答案 最快的方法是: proutil dbname -C tabanalys > dbname.tab 这是一个分
我正在创建某种音频播放器,但遇到了障碍。我添加了一个进度条,它会根据正在播放的歌曲进行更新。 但是,我希望进度条可以点击并在点击时跳转到轨道的时间(就像每个普通玩家一样)。
在我的进度应用程序中使用浏览器时,滚动条永远不会正常工作。它会显示我只能向下滚动一点,然后继续前进。这是一个正在进行的错误还是我可以做些什么来解决这个问题? /* Connected Database
我们如何更改 Progress 中的默认锁而不是共享锁? 最佳答案 您可以通过使用 [NO|EXCLUSIVE|SHARE]-LOCK 修饰符将锁定状态添加到查询来在每个单独的查询(FIND、FOR
我正在使用 Material-UI的 默认情况下转换 scaleX() 的组件 的属性在另一个里面 每当值更改以可视化当前进度时。它具有缓动效果,使一切看起来都很流畅,这通常非常好,但是出于我的应用程
我很好奇 PWA 添加到主屏幕后将在后台使用什么浏览器。它是您最初选择“添加到主屏幕”的那个吗?如果是,如果我在我的 Chrome 上将 PWA 添加到主屏幕怎么办手机,然后删除 Chrome(假设现
在我问任何问题之前,让我告诉你我对 Progress Openedge 没有任何经验,但我的公司运行一个用它制作的应用程序,现在我必须通过它进行一些 SOAP 调用。所以我想,为什么不调用用我认为合适
在我提出任何问题之前,让我告诉你我对 Progress Openedge 没有任何经验,但我的公司运行一个用它制作的应用程序,现在我必须通过它进行一些 SOAP 调用。所以我想,为什么不调用用我认为合
进度处理程序已在一些领先的 promise 库(Q、When、Bluebird)中弃用,并且也已从新的 Promises/A+ spec 中删除。虽然我理解取消进度事件背后的原因,但我在重构以下我
如何改变的颜色 progress[value]::-webkit-progress-value { background-color: #00bdf8;
我有一个需要连接的进度数据库。它们与 SQL Server Management Studio 的等价物是什么? 服务器似乎是 Progress OpenEdge 10.1 最佳答案 这在一定程度上取
我在不了解 PWA 的内在含义的情况下开始构建 PWA。当我搜索时,PWA 使用以下技术逐步为 Web 应用程序提供了类似于外观的原生应用程序 舱单 服务人员 设计App shell Web 应用程序
我是一名优秀的程序员,十分优秀!