Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
957 views
in Technique[技术] by (71.8m points)

objective c - Xcode: Getting warning "implicit conversion from enumeration type UIDeviceOrientation"

Full warning:

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

Getting it on the line:

[self orientationChanged:interfaceOrientation];

This is the method:

- (void)orientationChanged:(UIInterfaceOrientation)interfaceOrientation 

I can't really understand where this warning is coming from.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

UIDeviceOrientation refers to the physical orientation of the device whereas UIInterfaceOrientation refers to the orientation of the user interface. When you call your method

[self orientationChanged:interfaceOrientation];

you are most likely passing it a UIDeviceOrientation when you should, according to the method, be using a UIInterfaceOrientation.

Just to expand on this point a bit, UIDeviceOrientation is a property of the UIDevice class, and there are these possible values:

UIDeviceOrientationUnknown - Can't be determined

UIDeviceOrientationPortrait - Home button facing down

UIDeviceOrientationPortraitUpsideDown - Home button facing up

UIDeviceOrientationLandscapeLeft - Home button facing right

UIDeviceOrientationLandscapeRight - Home button facing left

UIDeviceOrientationFaceUp - Device is flat, with screen facing up

UIDeviceOrientationFaceDown - Device is flat, with screen facing down

As for UIInterfaceOrientation, it is a property of UIApplication and only contains 4 possibilities which correspond to the orientation of the status bar:

UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,

UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,

UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,

UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft

To get UIDeviceOrientation, you use

[[UIDevice currentDevice] orientation]

and to get UIInterfaceOrientation, you use

[[UIApplication sharedApplication] statusBarOrientation] 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...