Force multiplier to update on Interface Builder constraint

brandonscript

I've created a height constraint for a UIView in the Interface Builder that sets the height to = the superview. I set the multiplier to 1/3 of the superview's width. This works great, it sets the height, say on iPhone 5/5S, to ~107pts.

For wider screens, I want to set the multiplier to 1/4 instead; I suppose I could do this with Size Classes, but I'm not sure that's the best way to go for this?

In my viewWillAppear method of a view controller, I've tried doing the following; no matter what I do though, it still sets the height to only ~107pts. Note that _controlsAspectRatio is an IBOutlet to the IB constraint.

_controlsAspectRatio = [NSLayoutConstraint constraintWithItem:_controlsAspectRatio.firstItem attribute:_controlsAspectRatio.firstAttribute relatedBy:_controlsAspectRatio.relation toItem:_controlsAspectRatio.secondItem attribute:_controlsAspectRatio.secondAttribute multiplier:1.0f/4.0f constant:0];

// I've tried several combinations of several layout refresh options, to no avail
[_controlsContainer setNeedsUpdateConstraints];
[_controlsContainer setNeedsLayout];
[_controlsContainer layoutIfNeeded];
NSLog(@"%0.4f - %0.4f", _controlsContainer.frame.size.height, _controlsAspectRatio.multiplier);

// Output: 106.6667 - 0
brandonscript

Had to remove the original and add a completely new constraint:

NSLayoutConstraint* newControlsAspectRatio = [NSLayoutConstraint constraintWithItem:_controlsAspectRatio.firstItem attribute:_controlsAspectRatio.firstAttribute relatedBy:_controlsAspectRatio.relation toItem:_controlsAspectRatio.secondItem attribute:_controlsAspectRatio.secondAttribute multiplier:1.0f/4.0f constant:0];
[self.view removeConstraint:_controlsAspectRatio];
[self.view addConstraint:newControlsAspectRatio];
[_controlsContainer layoutIfNeeded];
NSLog(@"%0.4f - %0.4f", _controlsContainer.frame.size.height, newControlsAspectRatio.multiplier);

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

force database update to fail

분류에서Dev

Connection with Interface Builder, but UITableView is nil?

분류에서Dev

Xcode quit unexpectedly in interface builder

분류에서Dev

Interface builder had different items in the objecs library?

분류에서Dev

Trying to load a nib from interface builder

분류에서Dev

Update Flash Builder 4.6 to Air 15 on Mac

분류에서Dev

Why does generic interface constraint mess up the use of extension methods?

분류에서Dev

Force update view on change of computed property?

분류에서Dev

iOS - Is it possible to reset a label/textView to their initial state defined in Interface Builder?

분류에서Dev

Interface Builder에서 segue 라인 이동

분류에서Dev

receiving error Unknown class PFImageView in Interface Builder file for parse

분류에서Dev

New Interface Builder (Xcode 6) removes rect and kills design

분류에서Dev

Unknown class in Interface builder error after renaming UIViewController class

분류에서Dev

How properly add UITableView with prototyped cells in UIView in Interface builder?

분류에서Dev

When to draw controls manually and when to add via interface builder?

분류에서Dev

Xcode 6, Interface Builder 크기 문제

분류에서Dev

Interface Builder를 통해 UITextView에 '...'추가

분류에서Dev

Interface Builder의 Objective C 클래스 범주

분류에서Dev

Interface Builder에서 상수 사용

분류에서Dev

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

분류에서Dev

Cannot delete or update a parent row: a foreign key constraint in grails with mysql

분류에서Dev

MySQL: Cannot delete or update a parent row: a foreign key constraint fails

분류에서Dev

How to force google chrome sync to update site favicon

분류에서Dev

IBInspectable 문제 및 Interface Builder 용 xib에서 뷰로드

분류에서Dev

Interface Builder 설정을 Objective-C로 변환

분류에서Dev

Xcode Interface Builder-뷰가 수직으로 모호합니다.

분류에서Dev

Interface Builder 이상한 인터페이스 오류

분류에서Dev

Xcode 6은 Interface Builder를 지역화하지 않습니다.

분류에서Dev

Interface Builder와 연결되었지만 UITableView가 nil입니까?

Related 관련 기사

  1. 1

    force database update to fail

  2. 2

    Connection with Interface Builder, but UITableView is nil?

  3. 3

    Xcode quit unexpectedly in interface builder

  4. 4

    Interface builder had different items in the objecs library?

  5. 5

    Trying to load a nib from interface builder

  6. 6

    Update Flash Builder 4.6 to Air 15 on Mac

  7. 7

    Why does generic interface constraint mess up the use of extension methods?

  8. 8

    Force update view on change of computed property?

  9. 9

    iOS - Is it possible to reset a label/textView to their initial state defined in Interface Builder?

  10. 10

    Interface Builder에서 segue 라인 이동

  11. 11

    receiving error Unknown class PFImageView in Interface Builder file for parse

  12. 12

    New Interface Builder (Xcode 6) removes rect and kills design

  13. 13

    Unknown class in Interface builder error after renaming UIViewController class

  14. 14

    How properly add UITableView with prototyped cells in UIView in Interface builder?

  15. 15

    When to draw controls manually and when to add via interface builder?

  16. 16

    Xcode 6, Interface Builder 크기 문제

  17. 17

    Interface Builder를 통해 UITextView에 '...'추가

  18. 18

    Interface Builder의 Objective C 클래스 범주

  19. 19

    Interface Builder에서 상수 사용

  20. 20

    SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

  21. 21

    Cannot delete or update a parent row: a foreign key constraint in grails with mysql

  22. 22

    MySQL: Cannot delete or update a parent row: a foreign key constraint fails

  23. 23

    How to force google chrome sync to update site favicon

  24. 24

    IBInspectable 문제 및 Interface Builder 용 xib에서 뷰로드

  25. 25

    Interface Builder 설정을 Objective-C로 변환

  26. 26

    Xcode Interface Builder-뷰가 수직으로 모호합니다.

  27. 27

    Interface Builder 이상한 인터페이스 오류

  28. 28

    Xcode 6은 Interface Builder를 지역화하지 않습니다.

  29. 29

    Interface Builder와 연결되었지만 UITableView가 nil입니까?

뜨겁다태그

보관