2015-11-28 18 views
5

私はiPhone 4SのためのImageViewのための制約を変更しようとしているとのUIViewのための制約のviewDidLoadで、5,5Sを探す:iOSの8識別子

for (NSLayoutConstraint *constraint in logoImage.constraints) { 
    if ([constraint.identifier isEqualToString:@"logoTopIdentifier"]) { 
     constraint.constant=10; 
    } 
} 

それもループ内で反復していないようです。識別子を持つ特定の制約を得る他の方法はありますか?

+0

ストーリーボードに制約を追加すると、それを直接クラスにドラッグできます – Surely

+0

どういう意味ですか? – BlackM

+2

あなたは、storyboardのuibuttonをviewcontrollerクラスに接続する方法を知っていますか?同じ方法で、制約をviewcontrollerクラスに接続することができます。 – Surely

答えて

4

ストーリーボードの制約は、UIエレメントを接続するのと同じようにView Controllerクラスに接続できます。

ストーリーボードの制約を見つけ、ワークスペースを分割ビューにして、対応するビューコントローラークラスに制約をドラッグするだけです。

self.theConstraint?.constant = 100 
self.view.setNeedsUpdateConstraints() 
UIView.animateWithDuration(0.7) {() -> Void in 
    self.view.layoutIfNeeded() 
} 

ブロック:あなたが位置の変更をアニメーション化したい場合は

時には、次のような制約を更新することができます。

それです。

1

ここにはNSLayoutAttributeに基づいてviewから任意の定数にアクセスできるKVConstraintExtensionsMasterライブラリがあります。その制約がProgrammaticallyまたはInterface Builderのいずれであっても問題ありません。

[self.logoImage accessAppliedConstraintByAttribute:NSLayoutAttributeTop completion:^(NSLayoutConstraint *expectedConstraint){ 
     if (expectedConstraint) { 
      expectedConstraint.constant = 10; 

      /* for the animation */ 
      [self.logoImage updateModifyConstraintsWithAnimation:NULL]; 
     } 
    }];