1

私はプログラミングに慣れておらず、Objective C にも非常に慣れていないため、用語の誤りや、簡単な概念を実際よりも難しくしている可能性があることをお詫びします。

現在のデバイスに基づいて切り替えたい2つの非常に単純な整数配列があります

 int iPhoneDevice[2] = {320,410};
 int iPadDevice[2] = {768,1024};

現在のデバイスに基づいて、各配列を単一の変数に割り当てるにはどうすればよいですか??? これと同じ考えで。

if([[CurrentDevice] isEqualToString:@"iphone"]) {
        foo = iPhoneDevice[];      
    }else{
        foo = iPadDevice[];
    }

ポートレートに基づく次の条件ステートメントで、「foo」の両方の値を呼び出せるようにする必要があります。私の考えでは、ロジックはこれに似ています。

 if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        bar = foo[1];
    }else {
        bar = foo[0];
    }

追加のネストされた if で意図した結果が得られますが、コードを可能な限り圧縮/クリーンアップしようとしています。どんな助けでも大歓迎です。前もって感謝します。

4

3 に答える 3

2

私はこのようにアプローチします:

CGSize iPhoneDeviceSize = CGSizeMake (320, 410);
CGSize iPadDeviceSize   = CGSizeMake (768, 1024);
CGSize foo;

int bar;

// assign to foo the appropriate device size based on the user interface idiom
foo = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) ?
      iPadDeviceSize : iPhoneDeviceSize;

// assign to bar the width of the screen based on the orientation of the device.
bar = ([UIDevice currentDevice].orientation == UIInterfaceOrientationPortrait || 
       [UIDevice currentDevice].orientation == UIInterfaceOrientationPortraitUpsideDown) ?
      size.width : size.height;

それが完全にあなたが求めていたものかどうかはわかりませんが、あなたが提示しているコードに基づいて、私がしたいことです.

于 2012-04-28T05:43:39.493 に答える
1

デバイスがモバイルなのか iPad なのかを取得するには (偶然にも phone と pad と呼びます)、次のようにUIUserInterfaceIdiom( Pad/ Phone)を使用します。

if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
    //device is an iPad
   bar = foo[1];
else
    //Device is an iPhone/iPod Touch
    bar = foo[0];

または、スタイルを設定したい場合。

于 2012-04-28T05:36:24.670 に答える
1
int iPhoneDevice[2] = {320,410};
int iPadDevice[2] = {768,1024};

// I think this is the c syntax you're looking for
int *foo;

// CodaFi always has awesome amounts of knowledge handy
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
   foo = iPadDevice;
} else {
   foo = iPhoneDevice;
}
于 2012-04-28T05:41:03.923 に答える