How to detect the event when the user has ended the drag of a slider pointer?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- Popover segue to static cell UITableView causes co
I think you need the control event
UIControlEventTouchUpInside
.Connect
Touch Up Inside
andValue Changed
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:
In code:
If you want to wire it programatically you would have something like this in your viewWillAppear (or wherever it fits you) call:
The receiving method would look like this:
Swift 3.1
Sometimes you will want the slider's drag events to fire continuously, but have the option of executing different code depending on whether the slider is still being dragged or has just finished being dragged.
To do this, I've expanded on Andy's answer above that makes use of the slider's
isTracking
property. I needed to record two states:sliderHasFinishedTracking
andsliderLastStoredValue
.My code correctly:
doesn't fire an action upon starting drag
fires the action if the user only nudges the slider with a single tap (meaning that
isTracking
remainsfalse
)Try like this
Maybe you should add target for UIControlEventTouchUpInside、UIControlEventTouchUpOutside、UIControlEventTouchCancel events.
I met the same problem before , because i don't add target for UIControlEventTouchCancel event.