2013-03-14 61 views
1

在iPhone中我已经知道navigationbarbutton触摸也有一些扩展在导航栏下,但我需要限制用户交互只有一定的限制。我可以做到这一点。任何人都可以帮助我吗?限制导航栏按钮项中的触摸区域?

+0

一个快速的想法:使用可以把透明'UIView'所以你不能碰那部分! – Maulik 2013-03-14 07:40:17

+0

@maulik我有一个按钮只是在唠叨bar.so当我触摸该按钮有时导航栏按钮被调用... – hacker 2013-03-14 07:42:50

+0

然后,我想你必须改变按钮位置 – Maulik 2013-03-14 07:43:40

回答

0

实现轻击手势识别器并将您的控制器设置为委托。然后执行:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { 

    // [touch locationInView] -> gives the point where the user touched 
    // If the touch point belongs to your frame then return YES 
    // else return NO 

} 
0

可以实现自定义导航栏自己与隐藏的导航栏的“引擎”背后,让按钮上的自定义导航栏与所需的自定义行为/视觉效果。 如果您想实现手势逻辑(平移)切换导航页面,这也很有用。

AppDelegate.h:

@property (strong, nonatomic) UINavigationController *navigationController; 

AppDelegate.m:

YourMainViewController *yourmainViewController = [[YourMainViewController alloc] init]; 
_navigationController = [[UINavigationController alloc] yourmainViewController]; 
[_navigationController setNavigationBarHidden:TRUE]; 
[self.window setRootViewController:_navigationController]; 
[self.window makeKeyAndVisible]; 

YourMainViewController.m:实现自定义导航图像和添加按钮,您的视图使用Interface Builder编程或导航无论是。例如编程方式创建视图:

- (void)loadView { 
... 
    UIImageView *tmp_mynavbar = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CustomNavBG.png"]]; 
    tmp_mynavbar.frame = CGRectMake(0, 0, 320, 44); 
    [self.view addSubview:tmp_mynavbar]; 
    UIButton *tmp_addbutton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    tmp_addbutton.frame = CGRectMake(260, 10, 40, 20); 
    [tmp_addbutton setTitle:@"Add" forState:UIControlStateNormal]; 
    [tmp_addbutton setBackgroundImage:[UIImage imageNamed:@"CustomNavAddBtn.png"] forState:UIControlStateNormal]; 
    [tmp_addbutton addTarget:self action:@selector(pressedbuttonAddItem:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:tmp_addbutton]; 

// create button with the required size, user interaction area (add image then add transparent button with different size, etc) 
// also add a back button 
... 
} 

然后实现自定义导航按钮行为(添加/前进按钮也后退按钮)

-(void) pressedbuttonAddItem:(id) sender { 
    AppDelegate *app = (AppDelegate*) [[UIApplication sharedApplication] delegate]; 
    DetailViewController *detailViewController = [[DetailViewController alloc] init]; 
    [[app navigationController] detailViewController animated:YES]; 
} 

-(void) pressedbuttonBack:(id) sender { 
    AppDelegate *app = (AppDelegate*) [[UIApplication sharedApplication] delegate]; 
    [[app navigationController] popViewControllerAnimated:YES]; 
}