Logging touches' coordinates on ViewController - ios7

I have this newly created Empty project using XCode5. Added a storyboard with one blank View Controller. Created a custom view controller class.
Here's the question. How could I log or display the touches on this project?

You can use method - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

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

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/

iphone: How do I get the location of a touch down event?

I have an empty View-Based app. I'd like to do something with the x,y coordinates of every touch down on the screen. How do I do this?
Override the
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
function (from the NSRespondrer class). You can override it from your view class. The 'touches' variable hold a set of 'UITouch' instances that you can query for the location in the view.