Reputation: 195
I want some methods to be run when my user touches the screen, so implemented the touchesBegan:withEvent: method in my ViewController, but when I drag and dropped the scroll view onto my iphone, the touchesBegan:withEvent: method no longer gets called.
To try and fix I implemented the becomeFirstResponder method in my ViewController and told it to return YES;
and then in viewDidAppear method i called [self becomeFirstResponder];
however, after all this it did not work.
I also tried creating a custom scroll view and creating a ViewController object property in it, and then in the touchesBegan:withEvent: method for my custom scroll view I implemented it saying [self.mainViewController touchesBegan:withEvent]
so hopefully every time i touched the screen the touchesBegan method on my custom scroll view would get called, and then because of that my touchesBegan method in my vc would get called, but that wouldn't help either.
I also made an outlet of my scroll view to my vc and added a tap gesture recognizer to it and initiated it with a method and stuff and that worked the method i initiated with it got called but it was only after i touched up inside the screen, i want the method to get called as soon as i touch down the screen
any answers are muchly appreciated!
Upvotes: 0
Views: 405
Reputation: 195
In order to do this I just made my own custom scroll view class, and implemented the touchesBegan:withEvent: method in the uiscroll view with a delegate method I made.
So basically i just had to use delegation.
Upvotes: 0
Reputation: 596
override Touches end and if the user clicked instead of dragged I manually forward the message to first responder.
@interface MyScrollView : UIScrollView {
}
@end
@implementation MyScrollView
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
if (!self.dragging) {
[self.nextResponder touchesEnded: touches withEvent:event];
}
[super touchesEnded: touches withEvent: event];
}
@end
Upvotes: 3