在错误的位置添加带有框架显示的CAlayer

时间:2018-03-06 17:09:14

标签: ios uiview calayer

我试图在相机预览图层中添加一个矩形视图。我试过UIView和CALayer两种方式。在这两种情况下,帧值都相同,但它们最终都处于不同的位置。 enter image description here

一个黑色边框是CALayer(featureLayer),浅色背景是UIView(_cardHolder)。

在viewWillAppear中:

CALayer *featureLayer = [[CALayer alloc]init];
featureLayer.borderWidth=3;
featureLayer.backgroundColor=[[UIColor orangeColor]CGColor];
featureLayer.opacity = 0.5;
featureLayer.position = CGPointMake(0, 0);
[featureLayer setFrame:self.cardHolder.frame];

[self.videoPreviewLayer addSublayer:featureLayer];



(lldb) po featureLayer <CALayer:0x1c4423b20; position = CGPoint (160 283.5); bounds = CGRect (0 0; 288 181); allowsGroupOpacity = YES; opacity =
0.5; backgroundColor = <CGColor 0x1c40b1d00> [<CGColorSpace 0x1c00bb120> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 1 0.5 0 1 ); borderWidth = 3>

(lldb) po featureLayer.frame
(origin = (x = 16, y = 193), size = (width = 288, height = 181))

(lldb) po self.cardHolder <UIView: 0x123dcbc50; frame = (16 193; 288 181); autoresize = RM+BM; layer = <CALayer: 0x1c043eb40>>

(lldb) po self.videoPreviewLayer <AVCaptureVideoPreviewLayer:0x1c0623ae0; position = CGPoint (187.5
333.5); bounds = CGRect (0 0; 375 667); sublayers = (<CALayer: 0x1c0623800>, <CALayer: 0x1c4423b20>); masksToBounds = YES; allowsGroupOpacity = YES; inheritsTiming = NO; >

我错过了什么吗?

1 个答案:

答案 0 :(得分:-1)

将代码放在Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-03-06 18:25:17.342 ERROR 1768 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured. Reason: Failed to determine a suitable driver class / viewDidAppear以外的方法中的问题是真实的框架尚未呈现,所以它应该是这样但请记住将其包装在一次bool这个方法被多次调用

viewDidLayoutSubviews