ios - button能显示,但是没有点击事件,怎么处理
怪我咯
怪我咯 2017-04-17 17:40:14
0
4
291
  • (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];
    

}

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(4)
Peter_Zhu

See if self.userInteractionEnabled is YES.

迷茫

Suggestion: Use the layer viewer to see if there are any other Views covering the Button

小葫芦

Open view debug and check, or give the view a color to see if the view is set too small and the button is not in the display area of ​​the view

刘奇

For the reason why UIButton cannot be clicked, you can refer to this blog I wrote: http://www.hcios.com/archives/1066

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template