(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];
}
看看 self.userInteractionEnabled 是不是為 YES。
開view debug看下,或給view個顏色看看是不是view設定的太小,button沒在view的顯示區域裡
有關UIButton不能點擊的原因,可以參考下我寫的這篇部落格:http://www.hcios.com/archives/1066