Joe*_*ren 4 boolean objective-c return-value ios
这是关于shouldAutoRotateToInterfaceOrientation
视图控制器方法中return语句的语法的一个相当基本的问题.
为了允许除了颠倒的肖像模式之外的所有视图,我实现了以下代码块:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)
退货声明究竟在做什么?我知道它返回一个布尔变量,但它是如何确定是返回true还是false?这是return语句中的一种隐式if语句吗?即:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown)
return YES;
}
Run Code Online (Sandbox Code Playgroud)
技术上是一样的,只是更明确地说明了吗?
谢谢你的澄清!
比较的结果就像(something != something_else)
一个BOOL
值.如果比较结果为true,则表达式(....)
采用值YES
(与之相同TRUE
).
它不是隐式转换,而是比较的工作方式.
归档时间: |
|
查看次数: |
8403 次 |
最近记录: |