reliable way to get iPhone touch input? - iphone

I started using the MoveMe sample to get touch input working.
basically, I define these two callback functions to get my touch input:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for ( UITouch* touch in touches )
{
printf("touch down");
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for ( UITouch* touch in touches )
{
printf("touch up");
}
}
This works fine, until you have more than 5 touches on the screen at once. then it stops working properly, you won't get the "touch down" message if there are more than 5 touches on the screen. what is even worse is that you won't reliably get all of the "touch up" messages until you have removed ALL your fingers from the screen.
If you touch with 6 fingers, then release 3, then touch again with the other 3 still down, you will get the "touch down" but if you release it, some times you get the "touch up" sometimes you don't.
This pretty much makes it impossible to track touches, and usually results in a touch getting 'stuck' permanently down, when passed to my Touch Manager.
Are there some better apis to use to get touch input? is there at very least a function you can call to reliably get whether the screen is currently touched or not? that way I could reset my manager when all fingers are released.
EDIT:
right, there must be something I'm missing. because currently the calculator does something I cannot do with those callbacks.
it only accepts one touch at a time, if there is more than one touch on the screen it "cancels" all touches, but it must keep track of them to know that there is "more than one" touch on the screen.
if I touch the screen the button goes down, now if I add another touch to the screen, the button releases, cool, not allowed more than one touch. now, if I add 4 more fingers to the screen, for a total of 6, the screen should break, and when I release those 6 fingers, the app shouldn't get any of the "up" callbacks. yet when I release all of them and touch again, the button depresses, so it knows I released all those fingers!! how??

The problem you have is that the iPhone and iPod touch only support up to five touches at the same time (being fingers still touching the screen). This is probably a hardware limit.
(As St3fan told you already.)
The system will cancel all touches if there are more than 5 at the same time:
touchesCancelled:withEvent:
(This is probably what causes the odd behavior with only some touches calling touchesEnded:withEvent:)
If you want to know if a touch ended and it ended because it was lifted then make sure to check the UITouch's phase property.

It stops working because 5 is the max amount of touches that the iPhone and iPod currently support. No way around that I'm afraid.

Related

ignore touch events

I´m making a game with cocos2d and need to ignore touch events in some cases, esp. when another touch is "in progress".
It is, the player touches the screen, moves the finger around and then ends the touch. During this period, I need to ignore all other touches that may occur. How can I do that?
self.userInteractionEnabled = YES;

Detect multitasking gestures on iPad

In my iPad app,
If any app is running we can move the app horizontally by dragging the app screen horizontally by two or three fingers.
It is an inbuilt feature of an iPad, right.
Is there any notification or somethig so that I can be notified? When this happens.
Is there any way so that Ican disable this feature for my app.?
Code:-
WHILE TOUCHES MOVED CALL MY MAIN VIEW IS DISABLED AS REQUIREMENT, SO WHEN I AM DRAGGING THE SCREEN AS DESCRIBED ABOVE EVERYTHING FREEZS.
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if(self.tag==trackCell && (trackLifeCycle==1 || trackLifeCycle==2) && trackCell!=-2)
{
if(![[self superview] isKindOfClass:[AQGridView class]])
{
//NSLog(#"Touches Moved");
trackLifeCycle=2;
//////NSLog(#"Touches Moved at cell Starts%d",self.tag);
UITouch *T=[touches anyObject];
self.center=[T locationInView:[self superview]];
[delegate isOnHeaderView:self center:self.center];
//////NSLog(#"Touches Moved at cell Ends %d",self.tag);
}
}
}
The multitasking gestures use four or five fingers. You cannot disable them from within your app. The user can disable them for all apps in the Settings app (under the General section).
There is no notification specifically for the multitasking gestures. You will get UIApplicationWillResignActiveNotification when the user begins the gesture. If the user ends the gesture without switching apps, you will get UIApplicationDidBecomeActiveNotification. If the user does switch apps, you will get UIApplicationSuspendedNotification (which might not be public) and UIApplicationDidEnterBackgroundNotification.
If you had active touches when the user began the multitasking gesture, each touched view should get a touchesCancelled:withEvent: message, and each active gesture recognizer should set its own state to UIGestureRecognizerStateCancelled and send its action messages.

iPhone - Passing touch event to MPMoviePlayerController

Is it possible to pass touch event (by coding) to MPMoviePlayerController?
I don't want to detect touch. Just pass touch event.
I want to generate an event and pass it to MPMoviePlayerController as if user touched the player. Something like user touched the player at location x=100 and y=100
(I can't give in depth details due to some restrictions).
Have you tried extending the MPMoviePlayerController and just making sure all the touch events are passed.
You can even do this reverse to make sure the player view is being touched by adding your player view as a subview and then overloading the touch events in your Controller. Then print out the touch and you can see if the player passed the touch from its view to you.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(#"Video Touched?? %#",touches);
}
We need to place a transparent view over the movie player and handle touches for that view.

difference between touchMoved and Swipe?

i am rotating circle in iPad.i have inserted swipegesture event.but I want to different operations in touchMoved and swipeEvent.but when I do touch moving , swipw gesture is called, what i have to do , any help please?
swipe:
NSEventTypeSwipe
An event representing a swipe gesture.
Available in Mac OS X v10.6 and later.
Declared in NSEvent.h.
and
touchMoved:
Sent to the receiver when one or more fingers move in the associated view.
(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
so swipe cant be use to code some thing when any thing happens like touches.swipe is use for recognizing touch event.

Why is detecting touches getting slower and slower?

In my game if I play a particular game for several times, my touches need more time to be detected.
It stores all touches and then applies those touches all at the same time.
Can anybody tell me what's the problem?
In touchesBegan I wrote:
if (CGRectContainsPoint([tapView frame], [touch locationInView:self])
&& tapView.alpha == 1) {
[self callTapCode];
}
This is the code of touchesEnded. If I tapped and release the tapped it shows one tapping event.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (checkTap == TRUE && tapView.alpha == 1 )
tap_effect_view.alpha = 0;
}
- (void)callTapCode {
// Move player code by 6 pixels
// not possible to write all code
}
In tapView I continuously tap. callTapCode moves the player by six pixels. But after some time my touches detected very slowly, so that the player looks like he's jumping around. I played the game continuously 15 to 16 times.
You might work through this tutorial to learn how to use the Leaks Instrument. This is part of the Instruments suite that comes with Xcode, which will, among other things, help you track down memory leaks and general performance issues with your application.
I found the solution to my problem. In my game I had enabled the tapView.multipleTouchEnabled = TRUE
tapView is the view where I was continuously tapping.
When I make it FALSE it works.
i.e.
tapView.multipleTouchEnabled = FALSE;
I exactly dont know how. But it works.
Thanks for the replies.
Try to look for any memory leaks. Maybe the iPhone has to use virtual memory a lot.