Sorry if I overlooked a potential answer to my question, but I'm having trouble with using the UITapGestureRecognizer with a UILabel inside a subview UIViewController class...
Basically, I've created a custom UIViewController that has a UILabel and a few other irrelevant elements. This custom UIViewController, however, is inside a custom UIScrollView with paging enabled and the labels are offset just enough so you can see the next UIViewController's label. What I want to do is when the user touches the "next" label, the scrollRectToVisible:animated: method fires, essentially switching pages without scrolling. The CustomViewController's UILabels are situated on the top.
Here's an example code for the container UIScrollView when adding the UITapGestureRecognizer to the CustomViewController's UILabel:
[scrollView addSubview:CustomViewController];
- (void) addSubview: (CustomViewController *) view {
// create view's frame here...
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fireScrollRectToVisible:view)]; // this is the current problem like a lot of people out there...
[view.Label addGestureRecognizer:tap];
// [super addSubview:view.view];
}
- (void) fireScrollRectToVisible: (CustomViewController *) cvc {
CGRect frame = CGRectMake(cvc.view.frame.origin.x, cvc.view.frame.origin.y, 320, 480);
[scrollView scrollRectToVisible: frame animated:YES];
}
I initially thought this would be easy, but since the @selector doesn't allow you to place arguments it made it incredibly difficult. I think what I need is to access the CustomViewController's frame and set the scrollRectToVisible to that, but I'm not sure anymore...
I've tried this post but I'm very new at Objective-C and I don't fully understand the hitTest:withEvent: I'm assuming the hitTest:(CGPoint) has something to do with the view's bounds?
UITapGestureRecognizer initWithTarget:action: method to take arguments?
If anyone can point me in the right direction that would be great. Any help would be greatly appreciated!
If you need the frame of the view that contains the label that contains the gesture recognizer, couldn't you just do:
to get the frame?
The selector for your gesture recognizer should be of the form
the recognizer will get passed automatically if you set the selector to
@selector(gestureRecognizerDidFire:)
and you can access the view property therein.I do some change based on your code
hope this can help you.