好.我刚学习CALayers,因为我继承了别人的代码.有一个视图占据整个背景(减去工具栏),然后是一个子视图,占据了视图底部附近的一个小矩形.我正在尝试使用自动布局.这是我遇到麻烦的背
UIView *view = [self videoPreviewView]; CGRect bounds = [[self videoPreviewView] bounds]; //bounds gets set here //values are same as below [self setCaptureManager:captureManager]; AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[captureManager session]]; CALayer *viewLayer = [view layer]; [viewLayer setMasksToBounds:YES]; [captureVideoPreviewLayer setFrame:bounds]; //Use Autolayout off: x=0, y=0, width=320, height=504 //Use Autolayout on: x=0, y=0, width=0, height=0
谢谢.
启用autolayout后,尚未在viewDidLoad中计运算符视图约束,从而导致帧等于CGRectZero.您应该将帧设置代码移动到viewDidLayoutSubviews方法中.从类引用解释viewDidLayoutSubviews:
Notifies the view controller that its view just laid out its subviews.
正是在autolayout完成其工作以计算约束并将子视图放在适当位置之后.