// code in VIEwfinderVIEwController.m prevIEwLayer = [[AVCaptureVIDeoPrevIEwLayer alloc] initWithSession:captureSession]; prevIEwLayer.frame = self.vIEw.bounds; prevIEwLayer.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill; [self.vIEw.layer addSublayer:prevIEwLayer];
VIEwfinderVIEwController还进行一些视频处理,并提供框架的用户注册一些委托方法,以防发现感兴趣或在其中一个处理过的帧中找不到.
在我的实际应用程序的vIEwDIDLoad方法中,我创建了一个VIEwfinderVIEwController实例,设置它的框架并将其视图添加为子视图:
// code in the app's vIEw controller vIEwDIDLoad method VIEwfinderVIEwController *vfVC = [[VIEwfinderVIEwController alloc] init]; vfVC.vIEw.frame = self.vIEw.bounds; [self.vIEw addSubvIEw:vfVC.vIEw];
只要我无视旋转(我直到现在这样做),这样做很好.我的主要问题是,VIEwfinderVIEwController.vIEw调整了框架的大小,但AVCaptureVIDeoPrevIEwLayer却没有.我有点困惑:请不要自动调整prevIEwLayer的大小,因为对应于它的superLayer的视图是否正确调整大小?
有任何想法吗?我很乐意提供更多信息,但为了缩短问题,我现在不再进一步了解.谢谢.
解决方法 最后,我发现以下内容最适合我的应用.在我的应用程序中,我现在将VIEwFinderVIEwController添加为子视图控制器:
- (voID)vIEwWillAppear:(BOol)animated;{ if ([self.childVIEwControllers containsObject:self.vIEwfinderVIEwController] == NO) { [self addChildVIEwController:self.vIEwfinderVIEwController]; self.vIEwfinderVIEwController.vIEw.frame = self.vIEw.bounds; [self.vIEw addSubvIEw:self.vIEwfinderVIEwController.vIEw]; [self.vIEwfinderVIEwController dIDMovetoParentVIEwController:self]; }}
这样,willAnimateRotationToInterfaceOrIEntation:方法将被自动调用,我之前从视图控制器转发,它将取景器的视图添加为子视图.
此外,我在VIEwfinderVIEwController的这个方法中更新prevIEwLayer大小:
- (voID)vIEwWillLayoutSubvIEws;{ self.prevIEwLayer.frame = self.vIEw.bounds;}
我通过实现这两个方法来处理prevIEwLayer的旋转:
- (voID)willAnimateRotationToInterfaceOrIEntation:(UIInterfaceOrIEntation)toInterfaceOrIEntation duration:(NSTimeInterval)duration { [CATransaction begin]; [CATransaction setAnimationDuration:duration]; [CATransaction setAnimationTimingFunction:[camediatimingFunction functionWithname:kcamediatimingFunctionEaseInEaSEOut]]; [self updatePrevIEwLayerForOrIEntation:toInterfaceOrIEntation]; [CATransaction commit];}- (voID)updatePrevIEwLayerForOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation;{ // correct position of prevIEwLayer CGSize newSize = self.vIEw.bounds.size; self.prevIEwLayer.position = CGPointMake(0.5 * newSize.wIDth,0.5 * newSize.height); // rotate the prevIEwLayer,in order to have camera picture right switch (interfaceOrIEntation) { case UIInterfaceOrIEntationPortrait: [self.prevIEwLayer setAffinetransform:CGAffinetransformMakeRotation(0)]; break; case UIInterfaceOrIEntationLandscapeleft: [self.prevIEwLayer setAffinetransform:CGAffinetransformMakeRotation(M_PI/2)]; break; case UIInterfaceOrIEntationLandscapeRight: [self.prevIEwLayer setAffinetransform:CGAffinetransformMakeRotation(-M_PI/2)]; break; case UIDeviceOrIEntationPortraitUpsIDeDown: [self.prevIEwLayer setAffinetransform:CGAffinetransformMakeRotation(M_PI)]; break; default: break; }}
我希望这可以帮助每个将AVCaptureVIDeoPrevIEwLayer添加为子图层的人,并且在界面旋转时遇到调整大小和方向的问题.
总结以上是内存溢出为你收集整理的ios – 在旋转时自动调整AVCaptureVideoPreviewLayer大小的问题全部内容,希望文章能够帮你解决ios – 在旋转时自动调整AVCaptureVideoPreviewLayer大小的问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)