gpt4 book ai didi

objective-c - UIInterfaceOrientation 对象的返回值是否等于 bool 变量?

转载 作者:行者123 更新时间:2023-11-28 18:13:24 25 4
gpt4 key购买 nike

这是一个关于简单 UIInterfaceOrientation 对象的返回值的相当基本的问题,我尝试了以下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
BOOL orientacion = interfaceOrientation;
return orientacion;
}

并且转换完成了,所以我认为 UIInterfaceOrientation 对象等于 bool 变量?是隐含的拼写错误还是真正的 UIInterfaceOrientation 等于 bool 值..

最佳答案

UIInterfaceOrientation 是一个 enum,这实际上意味着它是一个整数。整数可以分配给 bool 值。许多事情都可以—— bool 值简单地等同于真或假。如果 bool 值设置为等于 0nil,则为 false。如果它设置为 任何 0nil (或其他一些 #defined 等价物),它将是真实的。由于 UIInterfaceOrientation 是枚举(整数),如果它等于 0,则 bool 值将为 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 会将 bool 值设置为 false;其他任何东西都会将其设置为 true。


无论如何,您没有正确使用此功能。该函数内的代码需要阅读:

if((interfaceOrientation == someOrientationYouWantToWork) || (interfaceOrientation == someOtherOrientationYouWantToWork)
{
return YES;
}
else
{
return NO;
}

someOrientationYouWantToWork 等设置为我在上面发布的枚举中的值。无论您想在哪个方向工作,请返回 YES。否则它将返回 NO

关于objective-c - UIInterfaceOrientation 对象的返回值是否等于 bool 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11381062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com