I have a UIView where I use the touchesbegan event, but I realized that once I put my finger on it, the touchesBegan event takes like 1 or 2 seconds to fire. How can I make this happen faster?
thanks!!!
After trying some stuff out, I realized that the delay happens only on custom UIButtons. If I "simulate" a button with a regular UIView subclass I get the correct behaviour.
Related
Is there a way to detect a click and hold within a NSView? I want to trigger an event after holding the mouse button down for 0.5 sec - similar to a longPressGesture in iOS.
I don't know of a specific selector for this, which is what it sounds like you're asking for, but you could, quite easily, handle this yourself.
Start a timer when the mouse down event occurs and when the amount of time has passed, react to it if the mouse up event did not occur before the specified elapsed time.
My slider sets a flag in ValueChanged and then resets it in TouchUpInside. However, when I touch the handle and slide it all the way to the end of the slider, the TouchUpInside event doesn't get fired (and hence my flag doesn't get reset).
Do I need to handle another UISlider action when I slide the handle to the end of the slider? I tried TouchCancel thinking that maybe it was getting cancelled when my finger moved past the end of the slider bar, but that didn't work.
To solve this, I needed to use the TouchUpOutside action/event.
I've got my custom NSView with a bunch of custom buttons in it, the buttons are added as a subView in the NSView's drawRect method.
Now I'm finding that after pressing a button the drawRect of the parent view is repeatedly called. Sometimes it only stops when I quit the app - I know this from a simple log statement in drawRect.
Now I know there are probably bigger architectural issues in my app causing this, where do I go to begin tracking down what's causing this view to be repeatedly redrawn?
Thanks!
First of all you shouldn't be adding subviews in drawRect:.
Are you doing any custom drawing or are you just adding subviews? If you're not doing any drawing, you should not implement drawRect:.
You want to add the subviews in initWithFrame: and then you want to set the frames of the subviews in layoutSubviews based on self.bounds.
If you have any questions, feel free to ask.
EDIT: Just realized that you were asking about NSView and not UIView. I've never used NSView, but perhaps they work similarly.
EDIT 2: I read a bit about NSView and it doesn't seem to have layoutSubviews. Perhaps you should set the frames in drawRect:? I'm still pretty sure you don't want to add subviews in drawRect:.
I've this problem:
in my game, when I tap a sprite, an animation in called. This animation is stored inside a singleton class (called Animation) that is inizialized in the didFinischLaunching method.
When I need for an action i use this code:
[self runAction:[[Animation sharedAnimation] animationName]];
On the device when I tap the sprite for the first time, occurs the following issues (one and only at the first tap):
There is a delay from the moment when I tap the sprite and the moment that the animation really starts;
In this interval (delay) the frame count collapses to 10fps (in some case even to 6fps)
This issues there aren't when I tap the same sprite for a second, third, etc times.
Ideas ??
Thanks very much!
Do you alloc the spriteframes in your animation init method?
If so, that's why.
Good luck!
I'm looking for the right way to handle "mouse held down in one spot" events in my NSView subclass.
I am familiar with Cocoa's mouseDragged: event, but it is only triggered when the mouse moves. If the mouse stays in the same position, no drag event is triggered. Similarly, mouseDown: is only fired when the button is first pressed. My view needs to perform an action as long as the mouse is held down in a particular region.
What is the proper way to do this kind of thing?
Can you start performing the action when you receive a mouseDown: event, and stop when you receive mouseUp: (or mouseDragged:, if you want to stop then, too)?
I'm not sure exactly what you're trying to accomplish, but if you want an action to be repeated at set time intervals after the mouseDown:, you could set a recurring NSTimer in the mouseDown: method that gets cancelled as soon as there is a mouseDragged: or mouseUp: event.