[英]Changing Y position constraints programmatically
我通過Xcode設置了約束,並且想以編程方式更改位置,但是它不起作用。 我是新來的,請幫忙。 我用了
[_btn_patientInformation.translatesAutoresizingMaskIntoConstraints: NO];
NSLayoutConstraint *constraintCoordinatesCenterY =[NSLayoutConstraint constraintWithItem:_btn_patientInformation attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:coordinatesView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:1];
但不幸的是,它不起作用。
將出口用於要更改的約束。
出口將如下所示:
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * topPositionConstraint;
將以上約束連接到情節提要中的Y約束。
要更改約束,您可以簡單地執行以下操作:
topPositionConstraint.constant=yourValue;
別忘了打電話
[self.view layoutIfNeeded];
改變約束之后。
嘗試通過以下方式設置約束:
現在,要上下移動所有這些按鈕,您只需更改第一個按鈕的頂部約束。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.