1
我在自定义标题中有一个后退按钮。有时点击区域是整个按钮。有时点击区域是按钮底部的一小部分。任何想法可能会导致这种情况?如果我使用轻击手势,则手势识别器停止发射事件。iOS按钮点击区域不一致
下面是它的样子。红色是按钮。蓝色是标题容器。绿色是内容布局中的标题标签。
初始化我的头视图。您可以看到该按钮位于顶层。其他内容都会添加到内容视图中,因此添加的任何元素都不应该影响可点击性。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CGFloat statusBarHeight = 0.0;//for iOS below 7.0
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;;
}
self.contentLayout = [[UIView alloc] initWithFrame:CGRectMake(0.0, statusBarHeight, frame.size.width, frame.size.height - statusBarHeight)];
[self addSubview:self.contentLayout];
CGFloat height = 44.0 < self.contentLayout.frame.size.height ? 44.0 : self.contentLayout.frame.size.height;
self.ivBack = [[UIImageView alloc] initWithFrame: CGRectMake(15.0, (height - 15.0)/2.0, 11.5, 15.0)];
[self.ivBack setImage:[UIImage imageNamed:@"back.png"]];
[self.ivBack setUserInteractionEnabled:YES];
[self.ivBack setHidden:YES];
[self.contentLayout addSubview:self.ivBack];
self.btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnBack setAccessibilityLabel:@"btnBack"];
[self.btnBack setFrame: CGRectMake(0.0, 0.0, 50.0, self.frame.size.height)];
[self addSubview:self.btnBack];
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
self.layer.shadowColor = [[UIColor colorWithRed:123.0/255.0 green:123.0/255.0 blue:123.0/255.0 alpha:1.0] CGColor];
self.layer.shadowOffset = CGSizeMake(0, 2.0);
self.layer.shadowRadius = 4.0;
self.layer.shadowOpacity = 0.7;
[self.btnBack setBackgroundColor:[UIColor redColor]];
[self.contentLayout setBackgroundColor:[UIColor blueColor]];
}
return self;
}
启用该按钮并为其分配单击事件。
-(void)addBackTarget:(id)target selector:(SEL)selector {
[self.ivBack setHidden:NO];
[self.btnBack addTarget:target action:selector forControlEvents:UIControlEventTouchDown];
}
该按钮将始终位于状态栏的“下方”,因此在屏幕截图中的配置中,点按按钮的顶部将在状态栏上注册为轻击,而不是在按钮上点按。 – bdesham
@bdesham正确。我没有点击状态栏。我点击状态栏下方的按钮。此外,左侧变得不可点击。 – JeffRegan