Can you attach a UIGestureRecognizer to multiple views?

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


        
12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 14:49

    Well if someone does not want to code for adding gesture view for multiple buttons like kwalker has answered above, and want to do it via Interface Builder this may help you.

    1) You can add Long Press gesture Recognizer from Object Library like you add other objects like UIButtons and UILabels.

    enter image description here Initially what I ended up using was I took only one

    2) Set referencing outlets to UIButton and sent actions with File's Owner.

    enter image description here

    Note: If you have multiple UIButton or any other object you will need separate gesture recognizer for each of them. For more details please refer to this question of mine.Getting wrong UIButton tag on Long press gesture recognizer

提交回复
热议问题