Triggering a UIButton's method when user drags finger into button's area?

前端 未结 3 1987
南方客
南方客 2021-01-18 12:46

I want to have a button that triggers its method under the following conditions:

  • When the user taps the button
  • When the user presses the button and dr
3条回答
  •  悲哀的现实
    2021-01-18 13:26

    You need to add the following UIControlEvents to your button:

    1. UIControlEventTouchUpInside
    2. UIControlEventTouchDragOutside
    3. UIControlEventTouchDragInside

    as such

        [self.myButton addTarget:self action:@selector(dragMoving:withEvent: )
                  forControlEvents: UIControlEventTouchDragInside | UIControlEventTouchDragOutside];
    
        [self.myButton addTarget:self action:@selector(dragEnded:withEvent: )
                  forControlEvents: UIControlEventTouchUpInside |
         UIControlEventTouchUpOutside];
    
        [self.myButton addTarget:self action:@selector(myButtonTouchDown:withEvent: )
                  forControlEvents: UIControlEventTouchDown];
    

提交回复
热议问题