【问题标题】:Opacity of dragging UIButton拖动 UIButton 的不透明度
【发布时间】:2017-05-10 17:05:47
【问题描述】:

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

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

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

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
}

【问题讨论】:

    标签: ios swift drag-and-drop opacity


    【解决方案1】:

    在 Interface Builder 中将 UIButton 的类型设置为“自定义”。这将在按住时停止褪色效果。

    【讨论】:

    • 差不多了。文本现在保持不变,但 BackgroundImage 仍然不透明,我可以阻止吗?
    • 试试draggingButton.adjustsImageWhenHighlighted = false
    • 成功了,我在 viewDidLoad 中设置了该属性,现在它似乎按预期工作了,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 2015-07-19
    • 2012-03-23
    • 1970-01-01
    • 2010-09-25
    • 1970-01-01
    • 2012-05-26
    相关资源
    最近更新 更多