0

UIBarButtonItem有一个setEnabled:方法(除了后退按钮之外的所有方法)按预期工作,但它没有setUserInteractionEnabled:方法。但在未启用时,UIBarButtonItems可以接收触摸,重新启用时,它们会尝试处理。我想setUserInteractionEnabled: NO 为我的导航栏按钮做相当于(在有时可能需要一段时间的操作期间)。

有没有一种我想念的简单方法来做到这一点?

4

1 回答 1

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];

希望对你有帮助...

于 2012-04-20T09:58:38.300 回答