對於Android的,你可以使用getRotation:
int rotation = getWindowManager().getDefaultDisplay().getRotation();
switch (rotation) {
case 0:
return Surface.ROTATION_0;
case 90:
return Surface.ROTATION_90;
case 180:
return Surface.ROTATION_180;
case 270:
return Surface.ROTATION_270;`
對於iOS this可能會有所幫助:
UIInterfaceOrientation orientation =
[UIApplication sharedApplication].statusBarOrientation;
if(orientation == 0) //Default orientation
//UI is in Default (Portrait) -- this is really a just a failsafe.
else if(orientation == UIInterfaceOrientationPortrait)
//Do something if the orientation is in Portrait
else if(orientation == UIInterfaceOrientationLandscapeLeft)
// Do something if Left
else if(orientation == UIInterfaceOrientationLandscapeRight)
//Do something if right
而且,這個線程也有類似的答案:Determining the Orientation of the screen rather than the orientation of the device
明天只能接受我的回答。會這樣做。 – Bypp