Подтвердить что ты не робот

Xcode: получение предупреждения "неявное преобразование из типа перечисления UIDeviceOrientation"

Полное предупреждение:

Implicit conversion from enumeration type 'UIInterfaceOrientation' to different enumeration type 'UIDeviceOrientation'

Получение информации о линии:

[self orientationChanged:interfaceOrientation];

Это метод:

- (void)orientationChanged:(UIInterfaceOrientation)interfaceOrientation 

Я не могу понять, откуда это предупреждение.

4b9b3361

Ответ 1

UIDeviceOrientation относится к физической ориентации устройства, тогда как UIInterfaceOrientation относится к ориентации пользовательского интерфейса. Когда вы вызываете свой метод

[self orientationChanged:interfaceOrientation];

вы, скорее всего, передаете его UIDeviceOrientation, когда вам следует, согласно методу, использовать UIInterfaceOrientation.

Просто чтобы развернуть эту точку немного, UIDeviceOrientation является свойством класса UIDevice, и есть следующие возможные значения:

UIDeviceOrientationUnknown - Невозможно определить

UIDeviceOrientationPortrait - Кнопка Home вниз вниз

UIDeviceOrientationPortraitUpsideDown - кнопка "вверх" вверх

UIDeviceOrientationLandscapeLeft - Кнопка "Главная", обращенная вправо

UIDeviceOrientationLandscapeRight - Кнопка "Главная", обращенная влево

UIDeviceOrientationFaceUp - Устройство плоское, экран вверх

UIDeviceOrientationFaceDown - Устройство плоское, экран вниз вниз

Что касается UIInterfaceOrientation, это свойство UIApplication и содержит только 4 возможности, которые соответствуют ориентации строки состояния:

UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,

UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,

UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,

UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft

Чтобы получить UIDeviceOrientation, вы используете

[[UIDevice currentDevice] orientation]

и чтобы получить UIInterfaceOrientation, вы используете

[[UIApplication sharedApplication] statusBarOrientation]