UIBarButtonItem, set exclusive touch

2019-06-17 06:12发布

Is there a way to make UIBarButtonItem exclusive touch? At the moment you can select multiple at the same time and it keeps crashing my application.

5条回答
Luminary・发光体
2楼-- · 2019-06-17 06:48

Slightly easier method than subclassing the navbar but the same idea;

for(UIView *temp in self.navigationController.navigationBar.subviews)
{
    [temp setExclusiveTouch:YES];
}

Put this just after you add your bar button items.

查看更多
萌系小妹纸
3楼-- · 2019-06-17 06:50

This does not work for UIBarButtonItem created using initWithTitle

查看更多
叛逆
4楼-- · 2019-06-17 06:56

In iOS 7 it wasn't working. I have used this method to try fix it.

for(UIView *temp in self.navigationController.navigationBar.subviews){
    [temp setExclusiveTouch:YES];
    for(UIView *temp2 in temp.subviews){
        [temp2 setExclusiveTouch:YES];
    }
 }
查看更多
Emotional °昔
5楼-- · 2019-06-17 07:00

Dredging up the past I apologise. I stumbled into this and hoped there was a better way than looping through subviews.

I found that the following makes the UIBarButtonItems exclusive:

[self.navigationController.navigationBar setExclusiveTouch:YES]; 

iOS7 may have made exclusive touch inherited.

查看更多
倾城 Initia
6楼-- · 2019-06-17 07:07

I managed this problem by subclassing UINavigationBar and overriding layoutSubviews method. Something like this:

- (void)layoutSubviews {
    [super layoutSubviews];
    for (UIView *view in self.subviews) {
        view.exclusiveTouch = YES;
    }
}
查看更多
登录 后发表回答