HOW TO IMPLEMENT AUTO LAYOUT WITH BUTTON ANIMATIONS?
OBJECTIVE- C
I am trying to implement NSLayoutContraints for 3 buttons I built programmatically. After clicking search, the three buttons move upward. However, I need autolayout to fix the contraints for iPhone 6, 5, and 4.
-(IBAction)Search:(id)sender { self.button.frame = CGRectMake(124, 475, 78, 72); self.buttonTwo.frame = CGRectMake(124, 475, 78, 76); self.buttonThree.frame = CGRectMake(124, 475, 78, 76); // animate [UIView animateWithDuration:0.75 animations:^{ self.button.frame = CGRectMake(13, 403, 78, 72); self.buttonTwo.frame = CGRectMake(124, 347, 78, 76); self.buttonThree.frame = CGRectMake(232, 403, 78, 76);
Auto Layout is a way that lets developer create user interface by defining relationships between
elements. It provides a flexible and powerul system that describes how views and UI controls relate tonech other. By using this , we can get incredablecontrol over layout, with a wide range of customization, and yeiled the perfect interface. Auto layout is compatable with many of Apple's most existing application programming interfaces, including animations, motions efects, and sprites.
Add the following constraints And try;
1. Assingn equal width frombutton 1 , button 2, button 3.
2. Assign horizontal space between both buttons.
3. Assign leading space from button 1, button 2, button 3.
4. Assign trailing space from button to its superview.
5. Assign top space toall the buttons.
TRy to set a macro for device width and height like;
OR TRY THE BELLOW ONE:
#define SCREEN_WIDTH [UIscreen main Screen].bound.size.width
#defineSCREEN_HEIGHT [UIscreen mainScreen].bound.size.height
andgive a frame button like this:
CGRectMake(SCREEN_WIDTH*0.05, SCREEN_HEIGHT*0.05, SCREEN_WIDTH*0.90, SCREEN_HEIGHT*0.08);
(OR)
Using self.view.frame.origin.x also helps but you should also
consider where you are setting frame for ur button. Means in
viewDidLoad, ViewWillAppear or somewhere else.
HOW TO IMPLEMENT AUTO LAYOUT WITH BUTTON ANIMATIONS? OBJECTIVE- C I am trying to implement NSLayoutContraints...