UIBarButtonItem
有一个setEnabled:
方法(除了后退按钮之外的所有方法)按预期工作,但它没有setUserInteractionEnabled:
方法。但是,虽然未启用,UIBarButtonItems
可以接收触摸,当重新启用时,它们会尝试处理。我想为导航栏按钮执行相当于setUserInteractionEnabled: NO
的操作(在有时需要一段时间的操作期间)。
有一种简单的方法可以解决这个问题吗?
答案 0 :(得分:0)
你需要做很少的定制,你可以做到......
//在viewDidLoad中添加此代码
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[leftButton setUserInteractionEnabled:NO];
[leftButton setImage:[UIImage imageNamed:@"navigationbutton.png"] forState:UIControlStateNormal];
leftButton.frame = CGRectMake(0, 0, 30, 30);
[leftButton addTarget:self action:@selector(yorrmethod) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
[leftButton release];
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[rightButton setUserInteractionEnabled : NO];
[rightButton setImage:[UIImage imageNamed:@"navigationbutton.png"] forState:UIControlStateNormal];
rightButton.frame = CGRectMake(0, 0, 30, 30);
[rightButton addTarget:self action:@selector(yourmethod) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
[rightButton release];
希望,这会对你有帮助......