UIInterfaceOrientation
是一個enum
,這基本上意味着它是一個整數。整數可以分配給布爾值。許多事情可以 - 布爾人簡單地等同於真或假。如果布爾值設置爲0
或nil
,則該值爲false。如果它設置爲任何其他以外的其他0
或nil
(或某些其他#define
d等價物),它將是真的。由於UIInterfaceOrientation是一個枚舉(整數),如果它等於0,布爾值將爲false。如果它不是0,那將是真的。
的UIInterfaceOrientation
值:
typedef enum {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottom
UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top
UIDeviceOrientationLandscapeLeft, // Device oriented horizontally, home button on the right
UIDeviceOrientationLandscapeRight, // Device oriented horizontally, home button on the left
UIDeviceOrientationFaceUp, // Device oriented flat, face up
UIDeviceOrientationFaceDown // Device oriented flat, face down
} UIDeviceOrientation;
此列表中的第一個將等於0
。接下來的1
,接下來的2
等。所以UIDeviceOrientationUnknown
將布爾值設置爲false;其他任何東西都會將其設置爲true。
在任何情況下,您都沒有正確使用此功能。這個函數中的代碼需要閱讀:
if((interfaceOrientation == someOrientationYouWantToWork) || (interfaceOrientation == someOtherOrientationYouWantToWork)
{
return YES;
}
else
{
return NO;
}
設置someOrientationYouWantToWork
等從我上面張貼的枚舉值。無論您想要工作的方向如何,請返回YES
。否則它將返回NO
。
yes我知道我提供的示例是一個不好的用法,現在我使用這個:if(interfaceOrientation!= UIInterfaceOrientationPortrait && interfaceOrientation!= UIInterfaceOrientationPortraitUpsideDown)orientation = true; } else { orientation = false; }返回方向; //同樣的:return UIInterfaceOrientationIsLandscape(interfaceOrientation); – xleonhart 2012-07-08 07:16:07
不錯的答案,小錯誤:你正在列出UIDeviceOrientation的值。 UIInterfaceOrientation可以在這裏找到:https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIInterfaceOrientation – katzenhut 2014-03-20 09:04:52