2011-08-04 87 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)的值,其可以是真或假。