Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
72 views
in Technique[技术] by (71.8m points)

ios - Change frame programmatically with auto layout

I have a UITableView with Auto Layout and I need to reduce the height when the GADBannerView appears at the bottom of the screen.

Unfortunately with Auto Layout it is impossible to modify the frame. The solution is to remove Auto Layout and set the frame manually. This is very dangerous because all my apps works fine on 3.5' and 4.0' displays and removing Auto Layout adds a new testing phase and more effort.

Is there a way to change the frame even if Auto Layout is enabled?

question from:https://stackoverflow.com/questions/23655096/change-frame-programmatically-with-auto-layout

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Let your UITableView constraints to bottom layout is set to 0, make an IBOutlet. Now let your GADBannerView height is 40 so change your outlet.constant = 40; For more about how to make IBOutlet and change its value have a look into this or this hope this will help.

Edit: For those who seeking for example, follow these simple steps (Because this is accepted answer, I think it is worth to have an example. Credit to @manujmv for this example)

  1. Create a height constraint for your view in your interface.

  2. Then add an IBOutlet object in your class for this constraint. For example:

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

Connect this object in your connection panel.

  1. Then change the value of this constraint whenever you needed

    self.heightConstraint.constant = 40;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...