xle*_*art 0 objective-c uiinterfaceorientation ios
这是一个关于简单的UIInterfaceOrientation对象的返回值的一个相当基本的问题,我尝试这个代码:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
BOOL orientacion = interfaceOrientation;
return orientacion;
}
Run Code Online (Sandbox Code Playgroud)
并且转换是这样做的,所以我认为UIInterfaceOrientation对象等于boolean var ?? 是一个隐含的拼写错误或真正的UIInterfaceOrientation等于布尔值..
UIInterfaceOrientation是一个enum,这实际上意味着它是一个整数.整数可以分配给布尔值.很多事情都可以 - 布尔人简单地等同于真或假.如果布尔值设置为等于0或nil,则为false.如果它被设置为除了或(或其他一些等价物)之外的任何东西,那将是真的.由于UIInterfaceOrientation是枚举(整数),如果它等于0,则布尔值将为false.如果它不是0,那将是真的.0nil#define
价值观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;
Run Code Online (Sandbox Code Playgroud)
此列表中的第一个将是相同的0.下一个1,下一个2,等等.所以UIDeviceOrientationUnknown将布尔值设置为false; 其他任何东西都会把它设置为真.
在任何情况下,您都没有正确使用此功能.这个函数里面的代码需要读取:
if((interfaceOrientation == someOrientationYouWantToWork) || (interfaceOrientation == someOtherOrientationYouWantToWork)
{
return YES;
}
else
{
return NO;
}
Run Code Online (Sandbox Code Playgroud)
将someOrientationYouWantToWorketc 设置为我在上面发布的枚举中的值.无论您想要工作哪个方向,都要返回YES.否则它会回来NO.
| 归档时间: |
|
| 查看次数: |
2159 次 |
| 最近记录: |