2017-03-22 3 views
1

장치가 세로 인 경우 비디오를 재생하는 컨테이너보기가 있습니다. 기기를 돌릴 때 동영상이 자동으로 전체 화면으로 재생되기를 원합니다. 나는 장치가 회전 할 때 감지이 코드를 해봤지만 전체 화면스위프트 3 - 가로로 회전 할 때 전체 화면으로 비디오 재생

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { 

    if (UIDevice.current.orientation.isLandscape) { 

     videoContainerView.frame = self.view.frame 
     // self.videoContainerView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height) // this didn't work to.... 
     print("Device is landscape") 
    } 
    else{ 
     print("Device is portrait") 
    } 

} 

비디오는 AVPlayer를 플레이어에에 컨테이너를 변경하지 않습니다. 감사의

+0

'layoutConstraints'에 의해 귀하의 문제를 해결할 수 있습니까? 'videoView'를'containerView'에 바인딩하십시오. – RrrangeTop

+0

이미 바인딩되어 있습니다 ... –

+0

회전했을 때 AvplayerController를 화면 크기로 설정하여 해결책을 찾았습니다. 이제 navbar를 닫는 방법을 찾아야합니다. –

답변

1

O.k. 그래서 AVPlayerLayer에 비디오를 추가하고 장치가 가로 방향 인 경우보기에 크기를 설정하여 비디오 전체 화면을 재생할 수있었습니다.

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { 

    if (UIDevice.current.orientation.isLandscape) { 

        DispatchQueue.main.async { 
         self.view.didAddSubview(self.controllsContainerView) 
         self.layer = AVPlayerLayer(player: self.player!) 
         self.layer?.frame = self.view.frame 
         self.layer?.videoGravity = AVLayerVideoGravityResizeAspectFill 
         self.view.layer.addSublayer(self.layer!) 

     } 
     print("Device is landscape") 
    } 

는 UIDevice.cuurent.orientation.islandscape는 == 오류 난 하층을 분리하고 videoContainer 경계 다시보기를 설정 한 경우.

else{ 
     print("Device is portrait") 
     movie.view.frame = videoContainerView.bounds 
     controllsContainerView.frame = videoContainerView.bounds 
     self.layer?.removeFromSuperlayer() 


    } 

누구에게 도움이되기를 바랍니다.

0

이 방법으로 컨트롤을 볼 수 있기 때문에이 문제를 해결할 수있는 또 다른 방법이 있습니다. 주요 개념은 AVPlayerViewController 객체를 새 하위 뷰로 이동하고 프레임을 전체 화면으로 설정하는 것입니다. 여기 내 코드는 ...

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { 

    if (UIDevice.current.orientation.isLandscape) { 


        DispatchQueue.main.async { 
         self.playerController.player = self.player 
         self.addChildViewController(self.playerController) 
         self.view.addSubview(self.playerController.view) 
         self.playerController.view.frame = self.view.frame 

     } 
     print("Device is landscape") 
    } 

장치를 세로 방향으로 다시 회전하면이 서브보기가 이전 프레임에 추가되고 크기가 다시 설정됩니다. 여기 내 코드가있다.

else{ 
     print("Device is portrait") 
     videoContainerView.addSubview(playerController.view) 
     playerController.view.frame = videoContainerView.bounds 
     controllsContainerView.frame = videoContainerView.bounds 
    } 
} 

희망이 있습니다. 행운을 빕니다!

관련 문제