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 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考