button能显示,但是没有点击事件,怎么处理

  • (id)initWithFrame:(CGRect)frame
    {
    self = [super initWithFrame:frame];
    if (self) {

       imgView=[[UIImageView alloc] initWithFrame:CGRectMake(0.f, 0.f, 1024.f, 768.f)];
       imgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
       imgView.backgroundColor=[UIColor clearColor];
       [imgView setImage:[UIImage imageNamed:@"tupian.jpg"]];
       [self addSubview:imgView];
       //[imgView.bringSubviewToFront];
    
       closeButton = [[UIButton alloc] initWithFrame:CGRectMake(900.f, 100.f , 40.f, 40.f)];
       closeButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
       [closeButton setTitle:@"touch" forState:UIControlStateNormal];
       [closeButton addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
       [closeButton setBackgroundImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
       [self addSubview:closeButton];
     

    }
    return self;
    }

  • (void)layoutSubviews
    {
    [super layoutSubviews];

}

  • (void)closeClick
    {

    NSLog(@" 广告");
    [self.ADViewDelegate addADView];
    [imgView removeFromSuperview];
    

}

阅读 6.4k
4 个回答

看看 self.userInteractionEnabled 是不是为 YES。

clipboard.png

建议: 使用图层查看器,看下有无其他View遮盖在Button上

开view debug看下,或者给view个颜色看看是不是view设置的太小,button没在view的显示区域里

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题