Как исправить ориентацию iOS с помощью нового API willAnimateRotationToInterfaceOrientation - PullRequest
0 голосов
/ 03 мая 2018

Я хотел бы обновить свое приложение из устаревшего 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 
}

Целью этого изменения является сохранение вращения камеры, ориентация должна быть неизменной. (Я использую EAGL и ручной дисплей AVFoundation в реальном времени).

AV-соединение все еще использует «Ориентацию», но новый API не предлагал их. Во всяком случае перевести его в ??? Спасибо

(также приветствуются коды Swift, мой старый проект написан на obj-c, но да, я могу читать swift)

1 Ответ

0 голосов
/ 03 мая 2018

Я бы пошел один из двух:

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection 
          withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator;
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection;

Здесь вы получаете UITraitCollection, который имеет (среди прочего) два свойства, horizontalSizeClass и verticalSizeClass. Эти классы размеров могут иметь значение UIUserInterfaceSizeClassCompact или UIUserInterfaceSizeClassRegular.

В зависимости от вашего устройства на iPhone Компактный / Обычный означает Портрет, а Компактный / Компактный переводится в Пейзаж.

Подробнее см. UITraitCollection .

...