(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];
}
See if self.userInteractionEnabled is YES.
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