• IOS UITapGestureRecognizer 遇到父view添加UIImageView的背景图片,子subview的tap事件不起作用了


    问题:遇到父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];

  • 相关阅读:
    表达式的计算
    树、森林、与二叉树的转换
    线索二叉树
    表达式树
    js正则表达式处理表单
    kmp匹配算法
    SQL练习题
    ajax添加header信息
    mvc中webapi添加后没法访问 解决办法
    mysql修改表引擎Engine
  • 原文地址:https://www.cnblogs.com/yuyu-2012/p/5091356.html
Copyright © 2020-2023  润新知