1

私のアプリでは、2 つのビューをそれぞれに応じて垂直にレイアウトする必要があり、iPhone 4 と 5 で同じように見えるようにしたいと考えています。コードは次のとおりです。

nextShowView = [[WestwoodNextShowView alloc]initWithFrame:CGRectMake(-5, 322, 290, 70)];
    nextShowView.staticLabel.text = @"Next Show";
    nextShowView.date.text = @"10/25";
    nextShowView.address.text = @"Green Dot Tavern";
    nextShowView.cityState.text = @"Detroit, MI";
    [_aboutScroll addSubview:nextShowView];

    playerView = [[WestwoodMusicPlayerView alloc]initWithFrame:CGRectMake(0, 407, 320, 50)];
        [_aboutScroll addSubview:playerView];

    NSDictionary * viewsDict = NSDictionaryOfVariableBindings(nextShowView, playerView);
    NSArray * constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[nextShowView]-15-[playerView]-20-|" options:NSLayoutFormatAlignAllLeft metrics:nil views:viewsDict];
    [_aboutScroll addConstraints:constraints];

私がやろうとしたことは、nextShowView と playerView の間に 15 ポイントのスペースを空け、playerView の下部からビューの下端まで 20 ポイントのスペースを空けることです。

助けてください !!!!

ありがとう、

4

1 に答える 1

0

Autolayout は、すべてのビューがそれを完全に指定するために必要なすべての制約を提供する場合にのみ機能します。との間の垂直方向の間隔だけでなく、nextShowViewとスーパービューplayerViewの間の垂直方向の間隔だけでなく、playerViewそれらの高さ、およびそれらの水平位置と幅も指定する必要があります。

ビューが期待する場所に表示されない場合は、制約が不十分である可能性があります。デバッガーで一時停止しpo [[UIWindow keyWindow] _autolayoutTrace]、コンソール コマンド ラインで言って、あいまいなレイアウトがあるかどうかを確認します。

于 2013-04-24T21:22:36.033 に答える