Can you attach a UIGestureRecognizer to multiple views?

前端 未结 12 993
忘了有多久
忘了有多久 2020-11-22 14:08
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTapTap:)];
[self.view1 addGestureRecognizer:tapGesture];         


        
12条回答
  •  旧巷少年郎
    2020-11-22 14:58

    A UIGestureRecognizer is to be used with a single view. I agree the documentation is spotty. That UIGestureRecognizer has a single view property gives it away:

    view

    The view the gesture recognizer is attached to. (read-only)

    @property(nonatomic, readonly) UIView *view

    Discussion You attach (or add) a gesture recognizer to a UIView object using the addGestureRecognizer: method.

提交回复
热议问题