0

これは、単純な UIInterfaceOrientation オブジェクトからの戻り値に関するかなり基本的な質問です。次のコードを試します。

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

変換はそれを行うので、UIInterfaceOrientationオブジェクトはブール変数と等しいと思いました?? 暗黙のタイプミスか、実際には UIInterfaceOrientation がブール値に等しいということです..

4

2 に答える 2

6

UIInterfaceOrientationは、enum本質的に整数であることを意味します。ブール値には整数を割り当てることができます。ブール値は単純に true または false に相当します。0ブール値がまたはに等しく設定されている場合nil、それは false です。or (またはその他のd に相当するもの) 以外に設定されている場合は true になります。UIInterfaceOrientation は列挙型 (整数) であるため、0 に等しい場合、ブール値は false になります。0 以外の場合は true になります。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;

このリストの最初のものは と等しくなり0ます。next 1、 next2など。UIDeviceOrientationUnknownブール値を false に設定します。それ以外は true に設定されます。


いずれにしても、この関数を正しく使用していません。この関数内のコードは次のようにする必要があります。

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

someOrientationYouWantToWork上に投稿した列挙型の値に etc を設定します。どのオリエンテーションで働きたい場合でも、戻っYESてください。それ以外の場合は を返しNOます。

于 2012-07-08T06:23:34.400 に答える
1

これはブール値ではなく、列挙値です。値が 0 以外の場合は、ブール値の "YES" にデフォルト設定され、それ以外の場合は "NO" になります。

于 2012-07-08T06:22:51.123 に答える