touchesEnded method doesn't get called? - objective-c

I am developing an application in which I use
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
}
-(void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
}
Now my problem in iphone 3 after touch move it is calling handleSingleTap function and touchesEnded didn't get called. This happen only on some lower part of the screen when I move there touch end didn't get called.If I move long then touchesEnded get called.
But this thing is working properly in IPhone4 and IPad.
In IPhone4 and IPad after touchsesMoved it is calling touchesEnded.

You're not the only one who has encountered this problem. I found a similar thread on Apple Support forum list : https://discussions.apple.com/thread/1507669?start=0&tstart=0
This thread dates from 2008 which coincides with the iPhone 3, so I guess there might be a chance this is an unfixed bug on iOS running on iPhone 3.
Otherwise if it's not the case, may be it's due to the fact that you are using a UIScrollView (whose controller is implementing the touch methods you listed above). By default, it has a method called :
delaysContentTouches
That is set to YES. May be you should change it to no and say how it behaves.
If you are not using a UIScrollView, may be you are using two view and the second view containing the "dead area" is not connected to your controller ?

Related

How do I forward touch events to a view behind a uicollectionview?

I have a uicollectionviewcontroller which I use to create a small toolbar at the bottom of the screen. I add the view of the uicollectionviewcontroller to another viewcontroller's view. My problem is that it won't forward touch events to a view underneath it. I did move it to the bottom and that worked for a while but now I need to use 2 uicollection views.
How am I supposed to forward touch events to views beneath a uicollectionviewcontroller's view?
In case the question is still relevant, the following can be used to achieve touch forwarding.
Subclass UICollectionView
Overwrite - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesEnded:touches withEvent:event];
[self.yourCustomDelegate forwardTouches:touches withEvent:(UIEvent *)event];
}
That is how UICollectionView can keep its ability to respond to user interaction, and the same time forward received touches.
As i think you can add your toolbar as footer of UICollectionView and it will work
have a look into this link How to Add Header and Footer View in UICollectionView

UIGestureRecognizer or touchesBegan not responding

I have a normal app. Yes this will not work anywhere in it. If I place this in a ViewController, it will not work, if I place this in a UIView subclass, likewise, it refuses to work. What am I doing wrong?
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(#"Please Work");
}
Make sure the view has userInteractionEnabled=YES. If a parent view has userInteractionEnabled=NO, the touches will be lost too. If that doesn't help, post code.

Affecting UIViewController from a child UIView

My question might sound rather strange, but still I didn't find any reference and I really need help.
so my point is, I have a ViewController which has a collection of UIViews, to be specific a subclass of UIView with
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
overridden
from this event i want to load a specific data (according on the UIView touched) on the UIViewController's child UIWebView
Is there a way to address parent ViewControllers children from the UIView that receives the action
Or am I looking into a completely wrong direction.
Any hel will be greatly appreciated, thanks in advance.
You can use delegate for example:
#protocol someProtocol
- (void)recivedTouch:(UITouch *)touch fromUIView:(UIView *)uiView;
in you view:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
[self.delegate recivedTouch:touch fromUIView:self];
}
View controller implemed method from delegate:
- (void)recivedTouch:(UITouch *)touch fromUIView:(UIView *)uiView
{
if (uiView == self.someView)
{
// do some stuff with uiWebView
}
}
try to look at it differently. Your touchesBegan shouldn't do anything which is not connected with the view. Your view is just a UI component, it shouldn't control application flow (data loading). That's the job of the view controller.
Look how UIButton is implemented. The button does not do anything when clicked. The controller has to tell it "this is the method that should be called when the user clicks you"
There are two ways how to tell the view what it should do for a specific action - creating a delegate or passing a selector that should be called.
Consider also extending UIControl, which has most of the actions already implemented.
Alternatively use NSNotificationCenter: Send and receive messages through NSNotificationCenter in Objective-C?
Send a message from your view, hook the message from your controller. Notificationas can get a bit messy though, the delegate is probably a cleaner solution

Get touch events in a UITextView

Apple does not provide touch event handling for UITextView. The project I'm developing includes notes that can be readable and editable, and I am using a UITextView. Please help me with this problem -- how can I get touch events for my project?
According to the Apple documentation, you may set a delegate for UITextView and implement the UITextViewDelegate.
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html
Specifically, you can determine that a UITextView was touched by implementing textViewShouldBeginEditing.
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
Be sure to set the delegate property on the UITextView in order to catch the event.
Just wanted to add to Kevin's answer. UITextView inherits from UIScrollView. You should be getting all the events declared in UIScrollViewDelegate protocol for the text view.
I got:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
when I declared my class as the delegate of UITextView.
Create custom textview and provide touch events inside the custom class. then you can create methods in delegate of that custom class.
I resolved the issue by using my own logic.
While reading we are adding a Custom View over the textview and working with those methods:
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
But when we are in the editing mode it is not possible anymore. Anyhow my requirement is only in readable mode.
Thanks for all your support to resolve the issue.

Detecting touches on a NSOpenGLView

I have added an NSOpenGLView to my MainMenu.xib file, and have implemented drawRect to draw to it, this works great, so far so good.
How do I detect touches on the screen? I imagine I could perhaps dump some transparent buttons or something over the NSOpenGLView area in Interface Builder?
The application is simple, i just need to know which area of a grid has been touched.
No need to add transparent buttons or overlays.
I'm assuming this is for the phone because you mentioned Cocoa Touch, but I'm not aware of NSOpenGLView for the phone. You need to look at the Apple example and create an EAGLView by overriding +layerClass in your subclass thus:
+ (Class)layerClass {
return [CAEAGLLayer class];
}
Next, Make sure "User Interaction Enabled" is checked in IB.
Finally, implement the touch method calls:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
These will tell you where users touched the surface, and with how many fingers. You can do the rest from there. Try creating the template OpenGL project and looking at that. In addition, Jeff LaMarche has some good iPhone OpenGL tutorials on his blog: http://iphonedevelopment.blogspot.com/