Reputation:
I have a view controller with half table view (bottom, 320x289)and half map view (top, 320,289). How can I detect location of tap?
Currently my code for the tap looks like this - when tapping, it hides the navigation bar so that the map gets some extra real estate. However, because it's not detecting location of the tap, when I tap on the tableview, I'm not able to segue into my table view controller.
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideShowNavigation)];
tap.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tap];
Ideally I would like to detect location of taps. If tapped at the top (if height <=289px), it hides navigation bar (or maybe even segue into a separate view controller where map is full screen). If tapped at the bottom (if height > 289px), then it pushes the segue into table view controller.
- (void) hideShowNavigation:(id)sender
{
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden];
[self hidesBottomBarWhenPushed];
}
Here's the whole code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationController.navigationBar.translucent = YES;
self.automaticallyAdjustsScrollViewInsets = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideShowNavigation:)];
tap.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tap];
}
- (void) hideShowNavigation:(id)sender
{
CGPoint = [sender locationInView:self.view];
CGFloat y = location.y;
if(y<=289){
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden];
[self hidesBottomBarWhenPushed];
}
}
Upvotes: 1
Views: 680
Reputation: 3848
In your selector:
CGPoint location = [sender locationInView:self.view];
CGFloat x = location.x;
CGFloat y = location.y;
Upvotes: 3