1

在 iphone 中,我知道导航栏按钮触摸在导航栏下也有一些扩展。但我需要将用户交互限制在一定范围内。我能做到这一点。有人可以帮我吗?

4

2 回答 2

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

}
于 2013-03-14T09:02:22.947 回答
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];
}
于 2013-03-14T10:27:22.480 回答