【问题标题】:How to detect gesture on a UIView after it becomes transparent?透明后如何检测 UIView 上的手势?
【发布时间】:2016-03-19 03:04:13
【问题描述】:

我在其他一些 UI 组件之上有一个 UIView 来检测长按手势。当长按开始时,我想通过将背景颜色更改为灰色和 alpha = 0.1 来提示用户。

长按结束后,UIView 必须改回为完全透明。我将它的 alpha 设置为 0,但问题是...

无法检测到其他客人。

mainView = UIView()
mainView.frame = ...
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action:Selector("longPressed:"))
mainView.addGestureRecognizer(longPressRecognizer)

func longPressed(sender: UILongPressGestureRecognizer) {
    let view = sender.view!

    if sender.state == .Began {
        view.backgroundColor = UIColor.grayColor()
        view.alpha = 0.1
    } else if (sender.state == .Ended || sender.state == .Cancelled || sender.state == .Failed) {
        view.backgroundColor = UIColor.whiteColor()
        view.alpha = 0
    }
}

什么是让这个UIView变回其原始状态的正确方法,以便在最初创建时可以检测到更多手势?

【问题讨论】:

    标签: ios swift cocoa-touch uiview


    【解决方案1】:

    将 UIView 的 alpha 属性设置为 0 将使其停止接收触摸。相反,当您希望它不可见时,将其背景设置为 UIColor.clearColor()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-03
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-05
      • 1970-01-01
      相关资源
      最近更新 更多