0
이것은 iPhone에서만 작동하는 코드입니다. 두 기기에서 실행되는 범용 앱을 만들고있어 동일한 앱입니다.자동 회전 코드는 iPhone에서 작동하지만 iPad에서는 작동하지 않습니다.
**//Automatically rotates the view to landscape
let orientation: UIDeviceOrientation = UIDevice.current.orientation
//If landscape right the rotate right
if orientation == UIDeviceOrientation.landscapeLeft
{
UIView.animate(withDuration: 0.5, animations:
{
() -> Void in
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
})
}
else
{
UIView.animate(withDuration: 0.5, animations:
{
() -> Void in
let value = UIInterfaceOrientation.landscapeLeft.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
})
}**