vikeyToy 2013-05-16 08:22 采纳率: 0%
浏览 4261

subView 的UIButton无法点击

代码:

UIButton *mainButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[mainButton setImage:[UIImage imageNamed:@"CircleShape.png"] forState:UIControlStateNormal];
mainButton.center = CGPointMake(self.view.frame.size.width/2.0f, self.view.frame.size.height/2.0f);
[self.view addSubview:mainButton];

UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 200, 100)];
[subView setBackgroundColor:[UIColor purpleColor]];
[mainButton addSubview:subView];

UIButton *secondButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[secondButton setImage:[UIImage imageNamed:@"CircleShape.png"] forState:UIControlStateNormal];
secondButton.center = CGPointMake(subView.frame.size.width/2.0f, subView.frame.size.height/2.0f);
[subView addSubview:secondButton];

为什么mainButton 可以点击,但是secondButton就不可以点击呢。

  • 写回答

3条回答 默认 最新

  • garaster 2013-05-16 09:26
    关注

    在self.view添加子view。

    UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 200, 100)];
    [subView setBackgroundColor:[UIColor purpleColor]];
    [self.view addSubview:subView];
    
    UIButton *secondButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [secondButton setImage:[UIImage imageNamed:@"CircleShape.png"] forState:UIControlStateNormal];
    secondButton.center = CGPointMake(subView.frame.size.width/2.0f, subView.frame.size.height/2.0f);
    [subView addSubview:secondButton];
    UIButton *thirdButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 0, 100, 100)];
    [secondButton setImage:[UIImage imageNamed:@"CircleShape.png"] forState:UIControlStateNormal];
    secondButton.center = CGPointMake(subView.frame.size.width/2.0f, subView.frame.size.height/2.0f);
    [subView addSubview:secondButton];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题