拖动UIButton的不透明度

时间:2017-05-10 17:05:48

标签: ios swift drag-and-drop opacity

我正在开发一个可以拖动按钮的应用程序。

我的问题是,在拖动时,不透明度非常低,按钮几乎不可见。我还没有找到我必须设置的内容,所以它与非拖动时保持一致。

我将目标设置为拖放,如下所示:

dragButton.addTarget(self, action: #selector(whileDragging), for: .touchDragInside)
dragButton.addTarget(self, action: #selector(afterDragging), for: .touchUpInside)

和whileDragging函数显示我尝试的内容:

@objc private func whileDragging(sender: AnyObject, event: UIEvent) {
    guard let control = sender as? UIControl else { return }
    guard let touches = event.allTouches else { return }
    guard let touch = touches.first else { return }

    let draggingButton = sender as! UIButton

    // Does nothing
    draggingButton.layer.opacity = 1
    draggingButton.alpha = 1
}

1 个答案:

答案 0 :(得分:0)

将UIButton的类型设置为' Custom'在Interface Builder中。这将在持有时停止褪色效果。