我有一个带有自定义 UIBarButtonItem 的 UINavigationBar (它使用 UIButton 作为其自定义视图)。问题是:自定义按钮的活动区域太大,如果我点击按钮外至少 40 像素,它仍然会被注册为点击按钮。这会导致意外点击。如何减少这些按钮的活动区域?
我也注意到了这个奇怪的现象。我发现使用容器 UIView 可以解决这个问题。例如:
UIButton *menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[menuButton addTarget:self action:@selector(revealMenu:) forControlEvents:UIControlEventTouchUpInside];
[menuButton setImage:[UIImage imageNamed:@"menuIcon"] forState:UIControlStateNormal];
UIView *menuButtonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[menuButtonContainer addSubview:menuButton];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuButtonContainer];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)