猿问

子viewController手势被父viewController拦截

如题,添加addChildViewController子viewController仍然无响应


- (void)viewDidLoad {
    [super viewDidLoad];    // Do any additional setup after loading the view.
    
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 200, 60, 60)];
    [btn setTitle:@"点我" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundColor:[UIColor blackColor]];
    [self.view addSubview:btn];
    
    [self addChildViewController:self.imgVC];
    
}

- (void)btnClick{    NSLog(@"点击了按钮");
    
}

// 懒加载- (addImgVC *)imgVC{    if (!_imgVC) {
        _imgVC = [[addImgVC alloc]init];
        [_imgVC.view setFrame:CGRectMake(0, 50, 375, 62)];
        [self.view addSubview:_imgVC.view];
        
    }    return _imgVC;
}


开心每一天1111
浏览 616回答 1
1回答

慕虎7371278

你的调用流程还是没弄清楚,把你的[self.view addSubview:self.imgVC.view]写在addChildViewController就可以了。因为你懒加载的时候,你写的流程是先添加了view,然后再添加子控制器,然而正确的流程是先添加子控制器,然后才能添加view
随时随地看视频慕课网APP

相关分类

iOS
我要回答