iPhone : How to detect the end of slider drag?

后端 未结 16 2669
不思量自难忘°
不思量自难忘° 2020-12-02 07:36

How to detect the event when the user has ended the drag of a slider pointer?

16条回答
  •  误落风尘
    2020-12-02 08:32

    I use the "Touch Up Inside" and "Touch up outside" notifications.

    Interface Builder:

    Connect both notifications in the Interface Builder to your receiving method. The method could look like this:

    - (IBAction)lengthSliderDidEndSliding:(id)sender {
        NSLog(@"Slider did end sliding... Do your stuff here");
    }
    

    In code:

    If you want to wire it programatically you would have something like this in your viewWillAppear (or wherever it fits you) call:

    [_mySlider addTarget:self
                  action:@selector(sliderDidEndSliding:) 
        forControlEvents:(UIControlEventTouchUpInside | UIControlEventTouchUpOutside)];
    

    The receiving method would look like this:

    - (void)sliderDidEndSliding:(NSNotification *)notification {
         NSLog(@"Slider did end sliding... Do your stuff here");
    }
    

提交回复
热议问题