Can you attach a UIGestureRecognizer to multiple views?

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


        
12条回答
  •  抹茶落季
    2020-11-22 15:12

    For Swift 3 in case anyone requires this: Based on Bhavik Rathod Answer above.

     func setGestureRecognizer() -> UIPanGestureRecognizer {
    
            var panRecognizer = UIPanGestureRecognizer()
    
            panRecognizer = UIPanGestureRecognizer (target: self, action: #selector(pan(panGesture:)))
            panRecognizer.minimumNumberOfTouches = 1
            panRecognizer.maximumNumberOfTouches = 1
            return panRecognizer
        }
    
            ///set the recognize in multiple views
            view1.addGestureRecognizer(setGestureRecognizer())
            view2.addGestureRecognizer(setGestureRecognizer())
    

提交回复
热议问题