Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.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 有人知道为什么else代码部分可以';不要隐藏我的颜色选择器?_Ios_Swift - Fatal编程技术网

Ios 有人知道为什么else代码部分可以';不要隐藏我的颜色选择器?

Ios 有人知道为什么else代码部分可以';不要隐藏我的颜色选择器?,ios,swift,Ios,Swift,我对Swift 4还是新手,我在互联网上找到了它,试图让这个按钮在图像按钮为A时显示“某物”。但当我再次单击按钮时,只有它的图像按钮改变了,但“某物”仍然没有隐藏。有人能帮忙吗 我已经完成了使用此动画的其他按钮,但该按钮显示了库中的另一个按钮。 但这1是不同的,不显示另一个按钮从图书馆,但显示ChromaColorPicker var sizeOff = UIImage(named: "Brush-Size") var sizeOn = UIImage(named: "Brush-Size-O

我对Swift 4还是新手,我在互联网上找到了它,试图让这个按钮在图像按钮为A时显示“某物”。但当我再次单击按钮时,只有它的图像按钮改变了,但“某物”仍然没有隐藏。有人能帮忙吗

我已经完成了使用此动画的其他按钮,但该按钮显示了库中的另一个按钮。 但这1是不同的,不显示另一个按钮从图书馆,但显示ChromaColorPicker

var sizeOff = UIImage(named: "Brush-Size")

var sizeOn = UIImage(named: "Brush-Size-On")
================================================其他地方======================

extension ViewController {

    @IBAction func BrushColourClicked(_ sender: UIButton) {
        if sender.currentImage == ColourOn {
            sender.setImage(ColourOff, for: .normal)
        } else {
            sender.setImage(ColourOn, for: .normal)
        } // Image first set
        configureUI()

    }

    func configureUI() {
        let colorPicker = ChromaColorPicker(frame: CGRect(x: 25.0, y: 410.0, width: 140.0, height: 140.0)) // Position & Size of Color Picker

        ColourButtonCenter = colorPicker.center
        colorPicker.center = BrushColour.center

        colorPicker.delegate = self
        colorPicker.padding = 5.0
        colorPicker.stroke = 3.0
        colorPicker.hexLabel.isHidden = true
        colorPicker.layout()
        view.addSubview(colorPicker)
        colorPicker.alpha = 0

        if BrushColour.currentImage == ColourOn {
            UIView.animate(withDuration: 0.35, animations: {
                colorPicker.alpha = 1
                colorPicker.center = self.ColourButtonCenter
            })
        } // Animation show
        else {
            UIView.animate(withDuration: 0.35, animations: {
                colorPicker.alpha = 0
                colorPicker.center = self.BrushColour.center
            })
        } // Animation hide
    }
}
我不知道
colorPicker.alpha=0

是否工作

每次调用
configureUI
时,您将向视图添加一个新的颜色选择器,然后在其上设置alpha动画

因此,当您试图隐藏
颜色选择器
时,实际发生的情况是,您正在添加一个带有
alpha 0
的新颜色选择器,并将其动画化为
alpha 0
(不做任何操作),以前的
颜色选择器
仍将可见,因此看起来好像没有任何更改


colorPicker
创建一个变量,并将其添加到视图中,然后在
configureUI
函数中配置该实例。

不应使用其
alpha
属性隐藏UI元素,应使用
ishiden
属性。与您的问题无关,但您还应遵守Swift命名约定,即变量和函数名的最小值(
colourButtonCenter
brushColourClicked
colourOn
colourOff
)@DávidPászor使用
alpha
而不是
ishiden
没有什么错。使用
alpha=0
查看与使用
ishiden=false
查看的行为相同。更改为ishiden后仍然没有发生任何事情,我将尝试找到真正的问题:或者感谢您的回答,我将尝试在configureUI中配置实例