好.我刚学习CALayers,因为我继承了别人的代码.有一个视图占据整个背景(减去工具栏),然后是一个子视图,占据了视图底部附近的一个小矩形.我正在尝试使用自动布局.这是我遇到麻烦的背景视图.我已经尝试固定宽度和高度以及我知道的其他一些东西,以使高度和宽度保持视图的大小(320 x 505).我不确定这些图层是否弄乱了我,或者它是否是另一种观点.无论如何这里是有问题的代码.关闭自动布局后,宽度和高度都是正确的.打开“自动布局”后,宽度和高度将变为负数并设置为零.有想法该怎么解决这个吗?
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,width=0,height=0
谢谢.