UIView animated changes with auto layout constraints
Try it as mentioned by shwet-solanki, but add the following line after changing the constraint:
[self.view layoutIfNeeded];
the IBAction would look like:
- (IBAction)expandYellowBox:(id)sender {[UIView animateWithDuration:0.5 animations:^{ self.yellowBoxHeightConstraint.constant += 50; [self.view layoutIfNeeded]; }];}
Where yellowBoxHeightConstraint
is the IBOutlet
for height constraint of yellowBox
.Hope this helps.
- Add Height constraint to both the views
- Create an IBOutlet for height constraint of yellowbox
- Now instead of changing the height of yellowbox in the button pressed event, rather change the value of the height constraint. i.e suppose your IBOutlet constraint name is yellowBoxHeightConstraint, then
yellowBoxHeightConstraint.constant += 50;
Hope this works for you.
//// WPViewController.h// AutoLayoutTEst//// Created by VASANTH K on 09/01/14.// //#import <UIKit/UIKit.h>@interface WPViewController : UIViewController@property (strong, nonatomic) IBOutlet UIButton *button1;- (IBAction)buttClicked:(id)sender;@property (strong, nonatomic) IBOutlet NSLayoutConstraint *heightConstrain;@property (strong, nonatomic) IBOutlet UIButton *button2;@end
click Event
- (IBAction)buttClicked:(id)sender { self.heightConstrain.constant=100;}
here u need to set the heightConstrain
for the Yellow button then create reference outlet for that button then update the heightConstrain
to update the size of that button it will automatically move your Red button down.
https://github.com/vasanth3008/AutoLayoutHeighDemo
refer my sample demo project