关于重用UITouch和UIEvent对象

时间:2018-06-19 13:23:21

标签: ios swift uitouch uievent

我试图了解UIEventUITouch对象的重用,所以我尝试测试,但结果使我感到困惑

这是我的代码

class CustomView: UIView {
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        print("==========================")
        print("Event Object : \(Unmanaged.passUnretained(event!).toOpaque())")
        for (index, touch) in touches.enumerated() {
            print("\(index)'s, UITouch Object : \(Unmanaged.passUnretained(touch).toOpaque())")
        }
        print("==========================")
    }
}

class ViewController: UIViewController {

    @IBOutlet weak var skyBlueView: CustomView!
    var previousTouch:UITouch?
    var currentTouch:UITouch?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.isMultipleTouchEnabled = true
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        print("==========================")
        print("Event Object : \(Unmanaged.passUnretained(event!).toOpaque())")
        for (index, touch) in touches.enumerated() {
            print("\(index)'s, UITouch Object : \(Unmanaged.passUnretained(touch).toOpaque()) Tap Count: \(touch.tapCount)")
        }
        print("==========================")
    }
}

我希望相同坐标的触摸对象相同

但结果不是。这是enter image description here我的结果

这是我的问题

  1. 何时释放UIEvent对象? UIEvent仍被重用

  2. 在同一坐标上,拍子计数增加,但是对象不同 如何在UITouch对象之间共享点击计数

  3. 发生了9次触摸,但是仅重用了4个UITouch对象(0x00007f9881c086f0、0x00007f9881d04000、0x00007f9881e02650、0x00007f988500c5c0)?如何运作?

0 个答案:

没有答案
相关问题