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

}

怪我咯
怪我咯

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

全部回覆(4)
Peter_Zhu

看看 self.userInteractionEnabled 是不是為 YES。

迷茫

建議: 使用圖層檢視器,看下有無其他View遮蓋在Button上

小葫芦

開view debug看下,或給view個顏色看看是不是view設定的太小,button沒在view的顯示區域裡

刘奇

有關UIButton不能點擊的原因,可以參考下我寫的這篇部落格:http://www.hcios.com/archives/1066

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板