how do i handle uislider's touch event in iphone? - objective-c

i want to fire a timer as user slides the slider when the touch ends.
is there a way to handle touch events of uislider?

Make sure your slider's continuous property is set to YES; then use -addTarget:action:forControlEvents: with... UIControlEventValueChanged?... in the usual way. The slider should continuously call whatever action method you give it.

I set the continuous property to NO and kept UIControlEventValueChanged and it manages to only fire off the event when the user releases the slider

Related

Cancel ccTouch on State Change in Cocos2d-iPhone

Could someone please help with with this issue that I am having with canceling touch event when my character dies. I have Character controller (Touch a sprite and drag left/right to move) based on screen X-axis. My controller class is a subclass of CCNode and has all the required methods to register touch with TouchDispatcher. The ccTouchBegin, ccTouchMove & ccTouchEnd works fine, but while my ccTouchMove is in action and my character dies I want to reset the controller, player position to a start location on the screen but that does not trigger until I lift my finger(thus ccTouchEnd) triggers then my reset player/controller in my GameLayer(CCLayer) fires.
I thought by adding the CCTouchCancel method would do the trick but it is not getting fired. Each of my Touch event methods first checks the controller's state (IDLE, ACTIVE, STOP) before doing any actions. I have an update method also to handle the dragging but it also checks that the controller.state == ACTIVE before allowing player to drag/move character.
In my Gamelayer's update method when my character dies, I set the controller.state = STOP. In the Controller's update method for STOP state, I call [[[CCDirector sharedDirector] touchDispatcher] removeDelegate: self]; which is the same code in the onExit method, but the touch event is not canceling. Touch event is only stopping if I lift my finger. Then the state change made in Gamelayer fires
Please advise.
I figured out why my character's controller was not changing state to STOP when my character dies. I had implemented the CCTouchCancel method but it was not getting triggered, thus the touch event was never cancelling until I lifted my finger off the screen.
I had implemented the update: (ccTime)delta method, in which I checking for ACTIVE state and performing some action. After commenting out the update method, everything worked as I expected. There was no need for the update method as the CCTouchMove method handles continuous touched location detection as long as the finger is touching the screen, no need to run an update method.

Tapped event fires before DoubleTapped event in WinRT

I have the follwing declaration:
<Button Tapped="Handler1" DoubleTapped="Handler2" />
Each time I double tap the button the Handler1 gets fired. Handler 2 never gets fired.
Thanks.
You can't do in this way because it will always fire the first event of tap. You can manage the double tap with the single tap event using a boolean or a counter to manage the following tap events.
I do not know why the DoubleTapped handler does not get called. It should. Maybe IsDoubleTapEnabled is set to false? This could not just happen by explicitly setting the property in XAML, but also e.g. by inheriting the value from a style.
But even when DoubleTapped works, the Tapped event will always fire once. The control is no fortune teller: When the first tap happens, it does not know that a second tap will soon follow, so it fires the Tapped event. If you do not want this, you need to implement your own behaviour and either ignore or delay Tapped events.
MSDN:
If a user interaction also fires DoubleTapped, Tapped will fire first to represent the first tap, but the second tap won't fire an additional Tapped. If you want different logic for Tapped versus DoubleTapped, your Tapped handler may need to use app-specific variables and a timer in order to avoid running on interactions that are eventually interpreted as a DoubleTap action.
But using double taps is generally discouraged by the UX guidelines. I would not use them with buttons, because buttons usually do not work that way and you are breaking user expectations.

Catch touch events anywhere onscreen in certain views?

I have a menu which I'd like to have automatically hide if it's inactive after a certain amount of time. This menu is composed of a hierarchy of UIViewControllers, which present various different views.
I'm thinking along the lines of running a timer, which invalidates and starts over whenever there's a touch.
Is it possible to catch all touch events in a set of UIViews? Perhaps just keep a boolean lying around and use the main UIWindow to catch touch events?
EDIT:
My app is a kiosk app of sorts, with a main screen and a menu. When the menu is up, I want it to run an auto dismiss timer, which resets after any touch in the entire menu screen. The menu is displayed over the entire screen, modally.
One way to be sure is to subclass UIApplication and override - (void)sendEvent:(UIEvent *)event method, every touch event happening in your app goes through this method and you can check the UIEvent type to see if it's UIEventTypeTouches and reset the timer.
Another way to do this simply involves adding a transparent layer over whole user accesible UI and override hitTest:withEvent:.
You can have an invisible view on top of your modals view controllers, and put have either a gesture recognizer on it which can start a timer, either a
-touchesBegan:withTouches
method, and then send to the .nextResponder the same method.

is there an event for holding a button

So of course there are events for UIControlEventTouchUpInside for button presses. But what I'm wondering is if you can tell when a button is held for a certain period of time?
There aren't any UIControlEvents that correspond to a long press but there is the UILongPressGestureRecognizer class that can be applied to any view object which will call back to a method via target/action when a long press is recognized.
UILongPressGestureRecognizer Class Reference
You can set up a timer when your button receives a touch down event. If the button receives a touch up event, invalidate the timer. If instead the timer fires, then the button has been held for your designated period and you can take whatever action you like in the firing method.
This is what I've done on OS X, where the situation is somewhat different. Letting the UIKit handle this via UILongPressGestureRecognizer, as suggested by Mark Adams, is probably the better idea.

How can I get the value of an NSSlider continuously?

It seems like NSSlider in Cocoa does not provide a delegate to receive an event like Value Changed for a UISlider.
How can I get the value of an NSSlider continuously and display it in an NSTextField, for example?
You need to research Cocoa's Target/Action mechanism. This is a basic Cocoa concept you'll need to understand. The slider (and any other control) can be given a target (some controller object) and an action (the method to call against that controller object).
The action is fired when the user stops dragging by default. Check the slider's Continuous property in Interface Builder to cause it to trigger the action as you're sliding it.
One advantage of using the timer approach is that it works for the case of using the keyboard rather than the mouse to adjust the slider. If the user has "Full Keyboard Access" turned on in System Preferences, they can use the Tab key to give the slider focus. They can then hold down an arrow key so that autorepeat kicks in, whereupon you have a similar situation to dragging with the mouse: the target/action is firing repeatedly, and you want to wait for a moment of calm before saving to the database.
You do need to be careful not to delete your NSTimer prematurely. For example, if the user quits the app during those couple of seconds you probably want to "flush" the slider value to the database before terminating the process.
Programmatical solution based on the answer of Joshua Nozzi:
Swift
slider.isContinuous = true
Objective-C
slider.continuous = YES;