2

私は、デバイスの種類ごとに要素のオフセットとサイズが異なる設計をしています。ポートレートの異なるiPhone(すべてコンパクト|レギュラー)に対して、ストーリーボードの制約に(サイズクラスなどを使用して)異なる値を設定する方法はありますか?

いいえの場合 — そのようなタスクを解決する最善の方法は何ですか?

アップデート

たとえば、ロゴがありますが、プラットフォーム (異なる iphone を含む) で、ロゴの上部オフセットが異なります (ポイントでも)。

そういうコードは避けたい

- (CGFloat)topLogoConstraintAccordingToSize:(CGSize)size {
    CGFloat top = 0;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        if (size.height > size.width){
            top = 56;
        } else {
            top = 35;
        }
    } else {
        if (IS_IPHONE_4){
            top = 36;
        } else if (IS_IPHONE_5){
            top = 22;
        } else if (IS_IPHONE_6){
            top = 50;
        } else if (IS_IPHONE_6_PLUS){
            top = 56;
        }
    }
    return top;
}

//宇宙の別の場所

self.logoTopConstraint.constant = [self topLogoConstraintAccordingToSize:size];

また、プラットフォームごとに個別のストーリーボードを作成したくありません。さらに悪いことです。

4

3 に答える 3

0

制約をコードビハインドと接続し、必要に応じて値を変更できます。

これは次のようになります: - .h ファイル内:

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraint;

-.m ファイル内:

if ([platform isEqualToString:@"iPhone3,3"])    constraint.constant=1;//put value you want instead of 1,2 and 3
if ([platform isEqualToString:@"iPhone4,1"])    constraint.constant=1;
if ([platform isEqualToString:@"iPhone5,1"])    constraint.constant=2;
if ([platform isEqualToString:@"iPhone5,2"])    constraint.constant=2;
if ([platform isEqualToString:@"iPhone5,3"])    constraint.constant=2;
if ([platform isEqualToString:@"iPhone5,4"])    constraint.constant=2;
if ([platform isEqualToString:@"iPhone6,1"])    constraint.constant=2;
if ([platform isEqualToString:@"iPhone6,2"])    constraint.constant=2;
if ([platform isEqualToString:@"iPhone7,1"])    constraint.constant=3;
if ([platform isEqualToString:@"iPhone7,2"])    constraint.constant=3;

しかし、あなたが何を達成しようとしているのか、私にはよくわかりません。すべての要素はポイント単位であり、見栄えが良いはずです (1x、2x、および 3x)。やりたいことをもう少し説明してもらえますか?

于 2015-01-15T12:48:01.563 に答える
-1

この行をヘッダーの下の AppDelegate.m に貼り付けます

 #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:(v) options:NSNumericSearch] != NSOrderedAscending)
 #define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

アプリケーションで起動しました

       UIStoryboard *mainStoryboard = nil;
      if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
   {


    if (IS_WIDESCREEN)
    {

        //4 inch screen
        mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];


    }
    else
    {

        if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
        {
            mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];

        }
        else
        {
            //3.5 inch screen
            mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_legacy_IPhone" bundle:nil];
        }
    }
} 
于 2015-01-15T13:07:25.450 に答える