2011-08-04 92 views
1
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 

    // Return YES if incoming orientation is Portrait 
    // or either of the Landscapes, otherwise, return NO 
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait) || UIInterfaceOrientationIsLandscape(toInterfaceOrientation); 

} 

什么的 '||'在这里呢?'||'在客观的C?

+1

''||手段或(布尔) –

+5

认真.....? (答案在你自己的代码样本中) – Jeroen

+0

你可以很容易地找到这个问题,而不要问这里... –

回答

9

同样的事情的C ||操作:logical or

+1

和C++,Java,C#一样,或几乎所有常见编程语言中的大部分。 – PeyloW

+0

是的,除了Objective-C || ||是C运算符,不同于语义。我认为语言之间可能存在一些优先级差异的顺序,但[我猜不是](http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages)(和圣洁的废话,我从来没有意识到&&有更高的优先于“||”,我想我总是使用parens,从来没有遇到过这个问题......) –

1

||是一个逻辑“或”操作 - 如果其至少一个操作数为真,则返回true。

而且,如果它的第一个操作数的计算结果为真它没有评价其第二个操作数时返回true。

0

表示OR。就像Obj-C使用它的方式一样。

|| = OR & & = AND

1

这是一个短路逻辑OR。

如果toInterfaceOrientation == UIInterfaceOrientationPortraitUIInterfaceOrientationIsLandscape(toInterfaceOrientation)返回true,但是第二个操作数只在第一个操作数为假时才会被计算。

0

该函数将返回一个布尔值true如果toInterfaceOrientation == UIInterfaceOrientationPortraitUIInterfaceOrientationIsLandscape()返回true。

0

在大多数编程语言中(值得注意的例外:Python,Ruby等)||是逻辑“或”运算符。

另请参见==(等于),!=(不等于)和& &(和)。

0

也许这意味着什么目标C不同,但在C,C++和Java的||运营商是logical OR

0

如果UIInterfaceOrientationPortrait等于toInterfaceOrientation那么它将返回true,否则将返回UIInterfaceOrientationIsLandscape(toInterfaceOrientation)的值,其可以是真或假。