我一直收到这个错误,当我滑过我的开关时,它的“开”和“关”状态在运行iOS 10.2的手机上不起作用。然而,当我点击它时,相同的开关会让它的状态被正确调用。我用一部运行着iOS 9.3的手机交叉检查了一下。在这里,当滑动手指或点击时,这两种状态都能正常工作。这是iOS 10.2的一个小错误,还是我的代码有问题(我不这么认为,因为它在9.3中可以正常工作)
我的代码
@IBAction func Switch_clicked(sender: AnyObject)
{
if switch_btn.on
{
print("button on")
self.EnableTouchID()
}
else
{
print("button off")
self.DisableTouchID()
}
}注意:主要问题是开关在没有调用.on或.off状态的情况下滑到" on“或"OFF”
发布于 2017-03-21 14:22:27
试试这个:
检查为其调用IBAction方法的UISwitch的event type。它一定是valueChanged。

@IBAction func onChangeSwitchState(_ sender: UISwitch)
{
if sender.isOn
{
print("button on")
}
else
{
print("button off")
}
}https://stackoverflow.com/questions/42919171
复制相似问题