La *_*sse 9 touchesbegan ios swift
我知道已经有一些问题,但我找不到解决方案.有一个非常简单的代码可以在我的一个项目上正常工作,但不能在另一个项目上工作:
这是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)
我确信解决方案很简单,但我找不到它.
Mic*_*lum 13
您需要确保userInteractionEnabled在视图的所有超级视图中启用了该功能.如果任何超级视图将此属性设置为false,则不会为他们或他们的任何子视图处理触摸事件.
| 归档时间: |
|
| 查看次数: |
11677 次 |
| 最近记录: |