Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios uicontrol状态”的用途是什么;申请书;你的按钮?_Ios_Swift_Uibutton_Uicontrolstate - Fatal编程技术网

Ios uicontrol状态”的用途是什么;申请书;你的按钮?

Ios uicontrol状态”的用途是什么;申请书;你的按钮?,ios,swift,uibutton,uicontrolstate,Ios,Swift,Uibutton,Uicontrolstate,我也看过了,但它只是说 其他控件状态标志可供应用程序使用 这只是一个getter方法,所以它什么时候设置?应用程序和保留基本上都是标记。这一点在查看objective-c文档时更为清楚: :uicontrolstatemabled=1我认为您的问题正文+标题有点误导,因为UIControlState.application根本不是特定于UIButton,它也不是一种方法。您是否询问UIControlState.application的用途以及任何UI元素的state属性在什么时候假定.appli

我也看过了,但它只是说

其他控件状态标志可供应用程序使用


这只是一个getter方法,所以它什么时候设置?

应用程序
保留
基本上都是标记。这一点在查看objective-c文档时更为清楚:


uicontrolstatemabled=1我认为您的问题正文+标题有点误导,因为
UIControlState.application
根本不是特定于
UIButton
,它也不是一种方法。您是否询问
UIControlState.application
的用途以及任何UI元素的
state
属性在什么时候假定
.application
值?请参见:@KKRocks我想OP已经看到了,因为引用的句子完全相同。您的覆盖变量看起来像是返回了UIControlState的数组它返回一个uicontrol状态,状态和customFlags异或在一起。这是怎么回事?@Brynjar-它们符合@Brynjar,它不像
XOR
那样工作,它是一个按位
或简单的
+
,因为在两个不同的标志中没有一个位是
1
。Thx。奥立的博客总是很好。好的,当然,按位OR,表示XOR将返回相同的结果;)
let myFlag = UIControlState(rawValue: 1 << 18)

class MyButton : UIButton {
    var customFlags = myFlag
    override var state: UIControlState {
        get {
            return [super.state, customFlags]
        }
    }

    func disableCustom() {
        customFlags.remove(myFlag)
    }
}
let myButton = MyButton()
print(myButton.state.rawValue) // 262144 (= 2^18)
myButton.isEnabled = false
myButton.isSelected = true
print(myButton.state.rawValue) // 262150 (= 262144 + 4 + 2)
myButton.disableCustom()
print(myButton.state.rawValue) // 6 (= 4 + 2)