Why doesn't UIView.exclusiveTouch work?

后端 未结 1 604
醉梦人生
醉梦人生 2020-12-15 08:33

In one of my iPhone projects, I have three views that you can move around by touching and dragging. However, I want to stop the user from moving two views at the same time,

1条回答
  •  时光说笑
    2020-12-15 09:25

    From The iPhone OS Programming Guide:

    Restricting event delivery to a single view:

    By default, a view’s exclusiveTouch property is set to NO. If you set the property to YES, you mark the view so that, if it is tracking touches, it is the only view in the window that is tracking touches. Other views in the window cannot receive those touches. However, a view that is marked “exclusive touch” does not receive touches that are associated with other views in the same window. If a finger contacts an exclusive-touch view, then that touch is delivered only if that view is the only view tracking a finger in that window. If a finger touches a non-exclusive view, then that touch is delivered only if there is not another finger tracking in an exclusive-touch view.

    It states that the exclusive touch property does NOT affect touches outside the frame of the view.

    To handle this in the past, I use the main view to track ALL TOUCHES on screen instead of letting each subview track touches. The best way is to do:

    if(CGRectContainsPoint(thesubviewIcareAbout.frame, theLocationOfTheTouch)){
        //the subview has been touched, do what you want
    }
    

    0 讨论(0)
提交回复
热议问题