xcode UIBarButtonItem,设置专属触摸
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11410379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIBarButtonItem, set exclusive touch
提问by Mike Mellor
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.
有没有办法进行UIBarButtonItem
独家触摸?目前,您可以同时选择多个,但它不断使我的应用程序崩溃。
回答by Mike Mellor
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.
在添加条形按钮项目之后放置它。
回答by kengura
I managed this problem by subclassing UINavigationBar and overriding layoutSubviews method. Something like this:
我通过继承 UINavigationBar 和覆盖 layoutSubviews 方法来解决这个问题。像这样的东西:
- (void)layoutSubviews {
[super layoutSubviews];
for (UIView *view in self.subviews) {
view.exclusiveTouch = YES;
}
}
回答by William George
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:
我发现以下使 UIBarButtonItems 独占:
[self.navigationController.navigationBar setExclusiveTouch:YES];
iOS7 may have made exclusive touch inherited.
iOS7 可能已经继承了独家触摸。
回答by fjtrujy
In iOS 7 it wasn't working. I have used this method to try fix it.
在 iOS 7 中它不起作用。我已经使用这种方法尝试修复它。
for(UIView *temp in self.navigationController.navigationBar.subviews){
[temp setExclusiveTouch:YES];
for(UIView *temp2 in temp.subviews){
[temp2 setExclusiveTouch:YES];
}
}
回答by Shilpi
This does not work for UIBarButtonItem created using initWithTitle
这不适用于使用 initWithTitle 创建的 UIBarButtonItem