问题:遇到父view添加UIImageView的背景图片,子subview的tap事件不起作用了
解决办法:
父view的UIImageView添加
headerImageView.userInteractionEnabled = YES;
详细代码:
UIImageView *headerImageView = nil;
headerImageView = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, headerView.frame.size.width, headerHeight-30)];//2015/12/30
NSLog(@"headerImageView.W = %f and headerImageView.H = %f",headerView.frame.size.width,headerHeight);
UIImage *image = nil;
if (image == nil) {
image = [UIImage imageNamed:@"icon_personal_banner.png"];
}
headerImageView.image = image;
headerImageView.userInteractionEnabled = YES;
UIImageView *avatarImageView = [[UIImageView alloc] initWithFrame: CGRectMake(headerImageView.frame.size.width - 70, headerHeight - 63, 60, 60)];
UIImage *avatarImage = [FunctionTools getAvatarByFileName: self.friendId];
if (avatarImage == nil) {
avatarImage = [UIImage imageNamed:@"default_header_image"];
}
avatarImageView.layer.cornerRadius = CGRectGetHeight(avatarImageView.frame)/2.0;
avatarImageView.layer.masksToBounds = YES;
avatarImageView.image = avatarImage;
[headerImageView addSubview: avatarImageView];
avatarImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchHeaderImageView:)];
[avatarImageView addGestureRecognizer: tap];