UIBarButtonItem, set exclusive touch

廉价感情. 提交于 2019-12-23 08:36:11

问题


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.


回答1:


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.




回答2:


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



回答3:


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.




回答4:


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



回答5:


This does not work for UIBarButtonItem created using initWithTitle



来源:https://stackoverflow.com/questions/11410379/uibarbuttonitem-set-exclusive-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!