相关疑难解决方法(0)

touchesBegan没有在UIView子类中调用

我知道已经有一些问题,但我找不到解决方案.有一个非常简单的代码可以在我的一个项目上正常工作,但不能在另一个项目上工作:

这是UIView的子类的代码.

import UIKit

class test : UIView {

    init(frame: CGRect, color: UIColor) {
        super.init(frame: frame)
        self.backgroundColor = color
        self.userInteractionEnabled = true
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
        super.touchesBegan(touches, withEvent: event)
        var alert = UIAlertView()
        alert.title = "lol"
        alert.message = "lol"
        alert.addButtonWithTitle("Ok")
        alert.show()
    }
}
Run Code Online (Sandbox Code Playgroud)

我确信解决方案很简单,但我找不到它.

touchesbegan ios swift

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

ios ×1

swift ×1

touchesbegan ×1