cannot update view.layer.frame in viewDidLoad?

前端 未结 5 1828
予麋鹿
予麋鹿 2021-02-19 18:59

I am trying to execute following code in viewDidLoad method of my single view controller project:

self.view.layer.frame = CGRectInset(self.view.layer.frame, 20,          


        
5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-19 19:51

    I also experienced this issue on Ray Wenderlich's tutorial 'Introduction to CALayers'. http://www.raywenderlich.com/2502/introduction-to-calayers-tutorial

    It seems shrinking the entire view controllers view is not the best thing to do. Instead create a sub view and call CGRectInset on that e.g in your view controllers viewDidLoad

    UIView *viewToManipulate = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0, self.view.bounds.size.width, self.view.bounds.size.height)];
    
    [self.view addSubview:viewToManipulate];
    
    viewToManipulate.backgroundColor = [UIColor redColor];
    viewToManipulate.layer.cornerRadius = 20.0;
    viewToManipulate.layer.frame = CGRectInset(self.view.layer.frame, 20, 20);
    

提交回复
热议问题