[英]BarButton Items are getting events while clicking on navigation bar
I am adding custom back button to navigation bar(custom navigation controller) like this:- 我在导航栏(自定义导航控制器)中添加自定义后退按钮,如下所示:-
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"goback.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(handleBackButtonClick) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 32, 32)];//same as image width and height
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
When I click close to bar button items(both left and right) the bar buttons are getting touch events. 当我单击靠近条形按钮项目(左右)时,条形按钮正在发生触摸事件。
I would like to prevent this weird behavior. 我想防止这种奇怪的行为。
I am developing app for iOS7
. 我正在为iOS7
开发应用程序。
I tried adjusting the width property of the barButtonItem and no luck. 我尝试调整barButtonItem的width属性,但是没有运气。
self.navigationItem.leftBarButtonItem.width = 32;
but I have an interesting solution for you, 但我有一个有趣的解决方案,
You can use two buttons in your custom view, one that implements that method you want, and other a dummy button 您可以在自定义视图中使用两个按钮,一个用于实现所需的方法,另一个用于虚拟按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"goBack.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(handleBackButtonClick) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 32, 32)];//same as image width and height
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
UIButton *dummyButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIBarButtonItem *dummyBarButton = [[UIBarButtonItem alloc] initWithCustomView:dummyButton];
self.navigationItem.leftBarButtonItems = @[barButton,dummyBarButton];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.