iOS 앱을 개발할 때, 미디어 재생 기능을 구현할 때 화면 회전과 Full-Screen 모드 처리는 중요한 요소입니다. 사용자가 영상이나 오디오를 볼 때 화면을 자연스럽게 회전시키고 Full-Screen 모드로 전환하여 더 좋은 경험을 제공할 수 있습니다.
화면 회전 처리
iOS 앱에서 화면 회전을 처리하기 위해서는 다음과 같은 단계를 따릅니다.
-
UIViewController의 shouldAutorotate 속성을 true로 설정하여 화면 회전을 허용합니다.
-
supportedInterfaceOrientations 함수를 오버라이드하여 허용할 화면 회전 방향을 지정합니다.
-
UIViewController의 preferredInterfaceOrientationForPresentation 속성을 오버라이드하여 초기 화면 방향을 설정합니다.
아래는 UIViewController의 화면 회전 처리 예시입니다.
class VideoPlayerViewController: UIViewController {
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .all
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeLeft
}
}
Full-Screen 모드 처리
미디어 플레이어를 Full-Screen 모드로 전환하려면 다음과 같은 단계를 따릅니다.
-
AVPlayerViewController를 사용하여 미디어 플레이어를 생성합니다.
-
entersFullScreenWhenPlaybackBegins 속성을 true로 설정하여 동영상 재생이 시작될 때 Full-Screen 모드로 전환됩니다.
-
exitsFullScreenWhenPlaybackEnds 속성을 true로 설정하여 동영상 재생이 종료될 때 Full-Screen 모드에서 일반 화면 모드로 복구됩니다.
아래는 AVPlayerViewController를 사용하여 Full-Screen 모드 처리하는 예시입니다.
let playerViewController = AVPlayerViewController()
let player = AVPlayer(url: videoURL)
playerViewController.player = player
playerViewController.entersFullScreenWhenPlaybackBegins = true
playerViewController.exitsFullScreenWhenPlaybackEnds = true
present(playerViewController, animated: true, completion: nil)
미디어 재생을 위한 화면 회전과 Full-Screen 모드 처리에 대한 내용을 정리해보았습니다. 미디어 재생을 제공하는 앱을 개발할 때 이러한 기능들을 적절히 활용하여 사용자에게 더 나은 환경을 제공할 수 있습니다.