entendendo o básico de auto layout usando xcode 6

Post on 07-Jul-2015

319 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Lightning talk sobre o básico de Auto Layout no XCode 6 no evento CocoaHeads RJ sediado no escritório do Hotel Urbano. Código dos exemplos: https://github.com/cytryn/AutoLayoutExample -- Lightning talk about the basics of Auto Layout on Xcode 6 at the CocoaHeads RJ event headquartered in the office of the Hotel Urbano. Examples found at: https://github.com/cytryn/AutoLayoutExample

TRANSCRIPT

André  CytrynCo-­‐fundador  Saída  Certa

@acytryn /andrecytryn/acytryn

Entendendo  Auto  Layout

• Possibilidades  de  layout;  

• Gerando  suas  constraints;  

• Resolvendo  ambiguidades;  

• Animando  com  Auto  Layout.

Possibilidades  de  layout

• Código;  • Xibs;  • Storyboard;  (recomendado)

Gerando  suas  constraints

• O  Xcode  deve  ser  capaz  de  calcular  como  uma  equação;  

• Existem  prioridades;  • Não  tenha  medo  de  criar  muitas  constraints.

Constraint  to  Margin  

• Nova  opção  para  iOS  8;  • DeTinir  uma  constraint  relativa  a  uma  margem  predeTinida  em  sua  superview.

Resolvendo  ambiguidades

• Frame;  • Constraint.  

Mais  uma  vez,  matemática!

Animando  com  Auto  Layout

Animando  sem  mudar  

constraint

Animando  mudando  a  constraint

@interface PlantZombieViewController : UIViewController

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

@property (nonatomic, weak) IBOutlet UIImageView *plantImageView;

@end

@implementation PlantZombieViewController

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. }

- (IBAction)smashButtonTapped:(UIButton *)button { if (self.plantTopConstraint.constant == 0) { button.titleLabel.text = @"SMASH"; [UIView animateWithDuration:1.0 animations:^{ self.plantTopConstraint.constant = self.view.frame.size.height - self.plantImageView.frame.size.height; [self.view layoutIfNeeded]; }]; } else { button.titleLabel.text = @"RESET"; self.plantTopConstraint.constant = 0; } }

- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }

@end

Exemplos

https://github.com/cytryn/AutoLayoutExample

Obrigado!  

Dúvidas?

@acytryn /andrecytryn/acytryn

top related