What happens when dragging off screen? - iphone

I have an object that can be dragged around. Once the user's finger goes off screen and comes back, I loose the ability to drag the object. If the user then does another touch and drag, everything is fine.
How can I get notified once the user's finger drags back onto the screen? Since touchesBegan doesn't fire, I don't get any notification.
Here is my touchesMoved, which I call in the touchesBegan:
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
//stop object dragging at edge of screen
if(location.x > 35){
myboject.center = location;}
}

The described behaviour seems normal to me, and all built-in Apple apps behave the same way. Since there’s no touch screen outside of the touch screen (yep), I believe there’s no way the device can distinguish between touch beginning or moving from outside of the screen.

Related

restart an uitouch

I've tried all morning, and start to think it's impossible.
So you have a touch in your screen, it entered the response chain and maybe did something. Then you moved it on the screen it called the touchesMoved: method (of the uiResponder associated with the touch) and maybe did other stuff.
At this point, is there anyway, that the touch continues to move in the screen, and when it enters some other uiView, the uiTouch gets reinitialized (I mean, call touchEnded, in the first uiView, then in the new uiView call touchesBegan, and then if continues movement call touchesMoved).
I've tried to resignFirstResponder and to manually call the methods, and I just can't.
I keep thinking that there should exist a really simple answer for this. Something like
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.superview];
if (!CGRectContainsPoint(self.frame, location)) {
[touch restart];
}
or
[[touch phase] restart];
(But anything in documentation ):
My recommendation would be to have the superview of all the views you want to transition through to receive the touches, then do a hit test on the subviews within the touchesMoved/Began/Ended methods (probably via CGRectContainsPoint(...)), and pass the touches along accordingly (calling the corresponding touchesBegan/Moved/Ended method on the subview).

How to determine x&y of last touch in multitouch scenario?

I'm new to this site and to iOS programming.
I am working on a percussion app. For this I want to know the x and y location of every finger that touches the screen. I thought this was straightforward, but multitouch is making things confusing for me.
Suppose the user has two fingers pressed on the screen and the user presses a third finger on the screen. How do I determine the location of this third finger?
My feeling is that I need to implement touchesBegan
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
To determine the x and y location I have to look at the touch that triggered this call to touchesBegan. But the touches are presented in an unordered set. If the third finger triggered this touchesBegan, then I have three touches in the NSSet. But since the set is unordered, how do I determine the touch that triggered this third call to touchesBegan? If I understand my documentation correctly it could be any of those three touches.
Many thanks in advance
Maybe you can add a simple counter property and increase its value in touchesBegan and decrease in touchesEnd.
Okay, it now turns out I have been mis-interpreting my test-data. If two fingers already touch the device when a third finger touches the device, only one UITouch object is part of the NSSet in the call to touchesBegan, and not three as I seemed to experience. This one UITouch represents the last fingertouch.
The only time when more than one UITouch object is passed to touchesBegan is when in fact multiple fingers begin to touch the device at the same time.
Since, in my case, I need to handle all new touches based on their location, I need to handle all UITouch objects in the NSSet.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for ( UITouch *touch in touches)
{
CGPoint location = [touch locationInView:self.view];
// Handle finger touch at given location
// ...
}
}

UIScrollView - detect second touch while scrolling

I have a subclass of UIScrollView that implements this method:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(#"touches: %d", [[event allTouches] count]);
[self.nextResponder touchesBegan:touches withEvent:event];
}
This gets called when I first touch the scroll view. However, if I begin dragging the scroll view, then place a second finger down, touchesBegan does not get called. I need to detect when a second touch has occured in the scrollview, even if it is currently scrolling. Any ideas?
EDIT: Two touches are registered if I start with two, but if I start with one, begin scrolling, then put a 2nd finger down it is not registered.
Make sure multipleTouchEnabled is set to YES on your scroll view.
You can also set this in Interface Builder. Look for 'Multiple Touch' checkbox.

iPad Simulator not receiving touch events outside of iPhone's 320x480 frame

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self.view];
NSLog(#"test x:%f",gestureStartPoint.x);
NSLog(#"test y:%f",gestureStartPoint.y);
etc..
Srangely, I'm not receiving any log statements if I click outside a 320x480 frame (starting from upper-left corner). Elsewhere in touchesBegan I call other methods passing in the touch and these weren't responding, so put these NSLogs in.
What do I have to do to receive touch events from the full 1024x768 view?
Is your UIView actually the full size of the window?
I think there's a bug in the "Upgrade Current Target for iPad" task.
I fixed this issue by creating a new "Window XIB" with iPad as the product, then replacing the Window object in MainWindow-iPad.xib with the Window object in the new XIB. (Be sure to update the "window" outlet of your app delegate.)

Touch Controls working on Simulator, not on Device

See topic. It's just with one application -- 2 of them work fine, but the third (and largest, go figure) doesn't respond to touch events. I tried changing a UIImageView's location on TouchesBegan, and that doesn't show up (but it does in the Simulator!)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self.view];
mothership.center = CGPointMake(80,80);
//etc...
I've tried both debug and release modes. Any idea on what would cause this? The rest of the game runs fine (enemy ships appear and shoot at you, so I know the rest of the code is working). Any advice is much appreciated. Thank you!
Don't respond to touches in the individual views. This can be problematic. Instead use the backing view to handle all touches. A good sample of this technique is in the Apple Sample Code: Touches
(requires dev login)
Weirdly enough, updating my ipod to 3.0 did the trick!