[英]Cannot assign value of type 'Bool' to type 'UIButton?'
I am trying to hide a button, until another condition is met. 我试图隐藏一个按钮,直到满足其他条件。 When i load the app i am using the slider and when it reaches the max, it should make the button visible, but for some weird reason it won't.
当我加载应用程序时,我正在使用滑块,当滑块达到最大值时,它应该使按钮可见,但是出于某些奇怪的原因,它不会。 I have just done it in another app with no issues and the code is almost identical.?
我刚刚在另一个没有问题的应用程序中完成了该操作,并且代码几乎相同。
Can't figure out what to do tbh. 无法弄清楚该怎么办。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
profileVisible.isHidden = true
}
@IBAction func btnClicked(_ sender: Any) {
motionManager.startDeviceMotionUpdates(to: queue) { (motion, error) in DispatchQueue.main.async {
self.slider.value = Float((motion?.attitude.roll ?? 0 ) * 1.4)
print(self.slider.value)
if self.slider.value == 1.0 {
self.profileVisible = false
self.motionManager.stopDeviceMotionUpdates()
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate); // vibrates when payment has succeded
}
if self.slider.value == -1.0 {
profileVisible = true
self.motionManager.stopDeviceMotionUpdates()
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}
}
}
You miss setting here 你错过这里的设置
if self.slider.value == 1.0 {
self.profileVisible = false
And here 和这里
if self.slider.value == -1.0 {
profileVisible = true
Should be 应该
profileVisible.isHidden = true/false // set it's value according to your logic
profileVisible
is of type UIButton
you need to set it's isHidden
property not it directly profileVisible
是UIButton
类型,您需要将其设置为isHidden
属性,而不是直接设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.