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
Since
UISlider
is a subclass ofUIControl
, you can set a target and action for itsUIControlEventTouchUpInside
.If you want to do it in code, it looks like this:
That will send you a
dragEndedForSlider:
message when the touch ends.If you want to do it in your nib, you can control-click your slider to get its connections menu, and then drag from the “Touch Up Inside” socket to the target object.
You should also add a target and action for
UIControlEventTouchUpOutside
and forUIControlEventTouchCancel
.If you don't need any data inbetween drag, than you should simply set:
This way you will receive
valueChanged
event only when the user stops moving the slider.Swift 4 and Swift 3
Add target for
touchUpInside
andtouchUpOutside
events. You can do it either programatically or from storyboard. This is how you do it programaticallyWrite your function to handle the end of slider drag
You can add an action that takes two parameters, sender and an event, for UIControlEventValueChanged:
Then check the phase of the touch object in your handler:
Swift 4
Note in Interface Builder when adding an action you also have the option to add both sender and event parameters to the action.
In Swift 4 you can use this function
1 Frist step:- Adding the target in slider
2 Second step:- Create a function
I had similar issue recently. Here is what I did in Swift:
The code that holds this continuous value reads:
The default seems to be YES (true). Setting it it to false does the thing you want.