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