[英]BarButton Items are getting events while clicking on navigation bar
我在导航栏(自定义导航控制器)中添加自定义后退按钮,如下所示:-
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];
当我单击靠近条形按钮项目(左右)时,条形按钮正在发生触摸事件。
我想防止这种奇怪的行为。
我正在为iOS7
开发应用程序。
我尝试调整barButtonItem的width属性,但是没有运气。
self.navigationItem.leftBarButtonItem.width = 32;
但我有一个有趣的解决方案,
您可以在自定义视图中使用两个按钮,一个用于实现所需的方法,另一个用于虚拟按钮
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.