我有一个具有半桌视图(底部,320x289)和半地图视图(顶部,320,289)的视图控制器。如何检测水龙头的位置?
目前我的水龙头代码看起来像这样 - 当点击时,它会隐藏导航栏,以便地图获得一些额外的空间。但是,因为它没有检测到水龙头的位置,所以当我点击桌面视图时,我无法进入我的桌面视图控制器。
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideShowNavigation)];
tap.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tap];
理想情况下,我想检测水龙头的位置。如果在顶部轻敲(如果高度<= 289px),它会隐藏导航栏(或者甚至可以将其划分为单独的视图控制器,其中地图是全屏的)。如果在底部点击(如果高度> 289px),则将segue推入表格视图控制器。
- (void) hideShowNavigation:(id)sender
{
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden];
[self hidesBottomBarWhenPushed];
}
以下是整个代码:
- (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];
}
}
答案 0 :(得分:3)
在你的选择器中:
CGPoint location = [sender locationInView:self.view];
CGFloat x = location.x;
CGFloat y = location.y;