Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用新API修复iOS方向WillAnimateRotationInterfaceOrientation_Ios_Objective C_Swift - Fatal编程技术网

如何使用新API修复iOS方向WillAnimateRotationInterfaceOrientation

如何使用新API修复iOS方向WillAnimateRotationInterfaceOrientation,ios,objective-c,swift,Ios,Objective C,Swift,我想从创建的API更新我的应用程序 从这个 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { // Camera rotation needs to be manually set when rot

我想从创建的API更新我的应用程序

从这个

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                         duration:(NSTimeInterval)duration {
  // Camera rotation needs to be manually set when rotation changes.
  if (self.previewLayer) {
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
      self.previewLayer.connection.videoOrientation = AVCaptureVideoOrientationPortrait;
    } else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
      self.previewLayer.connection.videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
    } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
      self.previewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
    } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
      self.previewLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
    }
  }
  self.dataOutput.previewFrameSize = self.previewLayer.frame.size;
}
对这个

- (void)viewWillTransitionToSize:(CGSize)size
       withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{
     // CODES HERE 
}
-(void)视图大小:(CGSize)大小
withTransitionCoordinator:(id)协调员{
//这里的代码
}
此更改的目的是保持摄影机的旋转、方向保持不变。(我正在使用EAGL和手动AVFoundation实时摄像头显示)

AV连接仍然使用“定向”,但新的API没有提供这种定向。不管怎样,把它翻译成???谢谢


(也欢迎使用Swift代码,我以前的项目是用obj-c编写的,但我可以阅读Swift)

我会选择其中一种:

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection 
          withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator;
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection;
-(void)将转换为跟踪集合:(UITraitCollection*)新集合
withTransitionCoordinator:(id)协调员;
-(作废)traitCollectionDidChange:(UITraitCollection*)以前的TraitCollection;
这里您可以得到一个
UITraitCollection
,它有两个属性,
horizontalSizeClass
verticalSizeClass
。这些大小类可以具有值
UIUserInterfaceSizeClassCompact
UIUserInterfaceSizeClassRegular

根据您的设备,iPhone上的Compact/Regular表示纵向,Compact/Compact表示横向

有关更多详细信息,请参阅