2015-10-12 24 views
1

我正在创建一个更高的导航栏,高度== 200,但是,当我点击下面的后退按钮时,它也会返航。iOS大小的导航栏后退按钮

enter image description here

这里是我的代码:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat screenWidth = screenRect.size.width; 

    navBar = [[SRNavigationBar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 200.0)]; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    [self.navigationController setNavigationBarHidden:YES animated:NO]; 
    [self.navigationItem setHidesBackButton:YES animated:YES]; 

    __weak id weakSelf = self; 
    self.navigationController.interactivePopGestureRecognizer.delegate = weakSelf; 

[self styleNavBar]; 
} 

- (void)styleNavBar 
{ 
    UINavigationItem *newItem = [[UINavigationItem alloc]initWithTitle:[[PFUser currentUser] objectForKey:@"nickName"]]; 

    UIBarButtonItem *menu = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)]; 
    newItem.leftBarButtonItem = menu; 
    newItem.leftBarButtonItem.tintColor = [UIColor colorWithRed:245/255.0 green:124/255.0 blue:0/255.0 alpha:1]; 

    [navBar setItems:@[newItem]]; 

    [self.view addSubview:navBar]; 
} 

- (void)back 
{ 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

任何帮助将不胜感激

回答

0

可以使用自定义按钮,使高度根据自己的需要

-(void)addLeftButton 
{ 
    UIImage *buttonImage = [UIImage imageNamed:@"btn_back.png"]; 

    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom]; 

    [aButton setBackgroundImage:buttonImage forState:UIControlStateNormal]; 

    aButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, 200.0); 

    UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton]; 

    [aButton addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; 

    [self.navigationItem setLeftBarButtonItem:aBarButtonItem]; 
} 
+0

我只是想浏览回来时,我正好点击图像上,没有在任何地方之下。我的问题是,为什么当我点击下面时,它会回到原点? –

+0

然后给它添加一个修复高度,这样它就不会对按钮 –

+0

下面的部分产生影响,否则它不起作用。我检查了视图层次结构,按钮框架正是我想要的,但仍然是它下面的整个区域仍然是可点击的 –

0

Apple技术支持:

我建议您避免在距离导航栏或工具栏近的 处有触敏UI。通常将这些区域称为 作为“斜坡因素”,使得用户更容易在按钮上执行触摸事件 而没有执行精确触摸的困难。 例如,UIButtons也是如此。但如果要在导航栏 或工具栏接收它之前捕获触摸事件,则可以继承UIWindow并覆盖: - (void)sendEvent:(UIEvent *)事件;

https://stackoverflow.com/a/9719364/2138564