AUTO LAYOUT IS A UNICORN

Similar documents
Mysteries of Auto Layout, Part 1

TL;DR: Interface builder is the tool within Xcode for creating a User Interface via a GUI.

Assignment III: Graphing Calculator

View Controller Lifecycle

Structuring an App Copyright 2013 Apple Inc. All Rights Reserved.

Xcode Release Notes. Apple offers a number of resources where you can get Xcode development support:

1 Build Your First App. The way to get started is to quit talking and begin doing. Walt Disney

Manual Xcode Ios 5 Simulator Black Screen >>>CLICK HERE<<<

Modern Auto Layout. Building Adaptive Layouts For ios. Keith Harrison. Web: useyourloaf.com Version: 1.0 ( ) Copyright 2018 Keith Harrison

In the first class, you'll learn how to create a simple single-view app, following a 3-step process:

CSC 581: Mobile App Development Spring 2018

High Performance Auto Layout

Xcode 6 and ios 8 What s New for Software Developers

Stanford CS193p. Developing Applications for ios. Fall Stanford CS193p. Fall 2011

ITP 342 Mobile App Dev. Interface Builder in Xcode

My First iphone App (for Xcode version 6.4)

ios Application Development Course Details

My First iphone App. 1. Tutorial Overview

Xcode Release Notes. Apple offers a number of resources where you can get Xcode development support:

Monitoring Tool Made to Measure for SharePoint Admins. By Stacy Simpkins

Learn to make desktop LE

iphone App Basics iphone and ipod touch Development Fall 2009 Lecture 5

Registering for the Apple Developer Program

My First Cocoa Program

The Best of Both Worlds: Using UIKit with OpenGL

ios DeCal : Lecture 2 Structure of ios Applications: MVC and Auto Layout

Hello! ios Development

CS193E: Temperature Converter Walkthrough

Assignment III: Graphing Calculator

CS193P: HelloPoly Walkthrough

COPYRIGHTED MATERIAL. 1Hello ios! A Suitable Mac. ios Developer Essentials

CS193p Spring 2010 Wednesday, March 31, 2010

Application Development in ios 7

CSC 581: Mobile App Development Spring 2019

Collection Views Hands-On Challenges

Advanced ios. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 20 11/01/2012

Designing iphone Applications

Manual Updating To Ios 7 Ipad 3 Not Working

Assignment II: Foundation Calculator

Manually Sync Itouch Touch Itunes Wont Let Me Update My Music To My

IOS 9 App Development Essentials: Learn To Develop IOS 9 Apps Using Xcode 7 And Swift 2 PDF

Stanford CS193p. Developing Applications for ios. Spring CS193p. Spring 2016

Learn to make watchosle

Stanford CS193p. Developing Applications for ios. Winter CS193p. Winter 2017

InfoSphere goes Android Flappy Bird

ios Mobile Development

ios 9 SDK Development

Iphone 4 Manual In Safari Slow 3g >>>CLICK HERE<<<

The MVC Design Pattern

Manual Of Ios 7.1 Beta 5 Iphone 4 Performance

Trash in the Dock. May 21, 2017, Beginners SIG The Dock (Part 3 of 3)

Stanford CS193p. Developing Applications for ios. Fall Stanford CS193p. Fall 2011

S A M P L E C H A P T E R

Staff Intranet Survey Results

ITP 342 Mobile App Dev. Interface Fun

19 - This PC Inside This PC

View Concepts. iphone Application Programming Lecture 4: User Interface Design. SDK provide many types of Views to show your content

Setting up a new ipad

Mobile & More: Preparing for the Latest Design Trends

Let s Make a Front Panel using FrontCAD

ipad Frequently Asked Questions Page 1

Assignment III: Graphing Calculator

Building Mapping Apps for ios With Swift

The purchaser of the ebook is licensed to copy ebook for use with immediate family members only.

What Does Manually Manage Music And Videos Mean In Itunes

Heuristic Evaluation of Covalence

Adopting Advanced Features of the New UI

Guide For Parking Administrators

Using PowerPoint - 1

Custom Drawing & Animation. CS 442: Mobile App Development Michael Saelee

This tool is actually pretty unique and has evolved over the last 7 years. I have been working with Adobe Connect for quite awhile now and one of the

Yahoo Error Code 21 Itunes Iphone 4s >>>CLICK HERE<<<

Manual Update Of Ios 7 For Iphone 4 Problems

Monday, 1 November The ios System

Why Model-View-Controller?

Setting Up Your ios Development Environment. For Mac OS X (Mountain Lion) v1.0. By GoNorthWest. 5 February 2013

ipad Settings Turn on icloud Backup Go to Settings, icloud. From here you can choose what items you want to have backed up.

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

Core Animation. Building Animated UI s. Bill Dudney. Gala Factory Software LLC. Bill Dudney Core Animation: Building Animated UI s Slide 1

Organize Your iphone: Icons and Folders

Salesforce Console Implementation Guide

Working with Wikispaces

Meet our Example Buyer Persona Adele Revella, CEO

EXCLAIMER CLOUD SIGNATURES FOR OFFICE 365. Deliver the most professional, intuitive and simple signature software designed for Office 365

Sync Manually Greyed Out Iphone Options >>>CLICK HERE<<<

A product of Byte Works, Inc. Credits Programming Mike Westerfield. Art Karen Bennett. Documentation Mike Westerfield

ios Developer s Guide Version 1.0

Prezi Creating a Prezi

Holy Family Catholic Primary School Computing Progression Map Year 1

BrandingUI (Basic, Advanced, Enterprise) Getting Started - Important First Steps

A Quick-Reference Guide. To access reddot:

Mobile Application Programming. Layout Techniques

Because you can t fix what you don t know is broken

News in RSA-RTE 10.1 updated for sprint Mattias Mohlin, April 2017

John Ray. Sams Teach Yourself. iphone. Application Development. Second Edition. S^/MS 800 East 96th Street, Indianapolis, Indiana, USA

Top 10 Productivity Tips in Fusion 360

Manual Update Of Ios 7 For Iphone 4s Release

Audience: Info Workers, Dev

Manual Safari Ios 7 Crash Iphone 5s >>>CLICK HERE<<<

The guide for the Merrill Mobile catalog available for tablet-based devices. Version 3.0

Transcription:

AUTO LAYOUT IS A UNICORN

WILD AND FREE.

MAGIK AWAITS, COME AND SEE.

Hi there folks! -Art credit: Elinor, 5 years old.

ABOUT ME

SousChef YOUR DIGITAL COOKING ASSISTANT 100K+ Users Mac, iphone, and ipad versions 300K+ User Contributed Recipes Recently acquired by a UK Company

Nice Mohawk

Ita A FINE LIST-MAKING APP Universal ios App icloud Documents and Data Hit Top 100 in USA Recently had a 75K d/l day during promotion

Ita 2 A FINER LIST-MAKING APP ios 7 re-envisioning Slick inline editing mode Built on Text Kit In-app settings UIDynamics

Reverb A COMPLETELY NEW WAY TO DISCOVER NEWS SF Bay Area Client Interesting move into the News discovery market NML hired to do animations and social integrations, push notifications ipad only

THE FINE EDGE nicemohawk.com/blog

AUTO LAYOUT

This is how it s going to go. I'm not really going to talk about the wiz-bang stuff. We're mostly going to talk about the pain in the ass, kind of esoteric stuff. Auto Layout Basics Animation Debugging Advanced Stuff DISCLAIMER: AUTO LAYOUT IS SOMETIMES HARD AND I M IN IT WITH YOU, I'VE REVERTED AT LEAST A FEW PROJECTS TO FRAMES, SPRINGS AND STRUTS.

Auto Layout Auto Layout is sometimes referred to as constraint based layout system. You create a set on constraints and the Auto Layout Engine solves them. This means you need an unambiguous set of constraints. Which usually means two or more constraints for each axis. DISCLAIMER: AUTO LAYOUT IS SOMETIMES HARD AND I M IN IT WITH YOU, I'VE REVERTED AT LEAST A FEW PROJECTS TO FRAMES, SPRINGS AND STRUTS.

The Architecture Update Constraints Layout Views Display Views

The Architecture Update Constraints Layout Views Bottom up Subview Constraints Container View Constraints View Controller Level Constraints Trigger with -(void)setneedsupdateconstraints; Override point: - (void)updateviewconstraints; // Overrides must call super or send -updateconstraints to the view. Subview Container View View Controller Display Views

The Architecture Update Constraints Layout Views Display Views Top down Layout View Controller s view Layout Container View Layout Subview Trigger with -(void)setneedslayout; Override point: - (void)layoutsubviews; // Overrides must call super Subview Tip: Force layout with -(void)layoutifneeded Container View View Controller Tip: Force layout with -(void)layoutifneeded

The Architecture Update Constraints Layout Views Top down Draw View Controller s view Draw Container View Draw Subview Trigger with -(void)setneedsdisplay; Override point: - (void)drawrect:(cgrect)rect; // Overrides *may* call super. Subview Container View View Controller Display Views

THINGS YOU SHOULD KNOW IF YOU RE A BABY UNICORN

Constraints!

Constraints! [NSLayoutConstraint constraintswithvisualformat:@ H: -[view]- " options:0 metrics:nil views:nsdictionaryofvariablebindings(view)];

Constraint Maths attribute1 = multiplier * attribute2 + constant view.x = superview.leading + 20 Constraints also support >=, <= and priorities

Constraints not frames! Do not edit view.frame manually Unless you want a migraine. Reading from view.frame is fine, just do it after -layoutsubviews

Alignment Rects not frames! Alignment rects give you a lot of flexibility view.alignmentrectinsets alignmentrect -alignmentrectforframe: -frameforalignmentrect: frame

Interface Builder Interface Builder in Xcode 5 is usable. Alignment Constraint Issues Auto Layout tools are hidden stored here: Now supports ambiguous layouts, easy alignment and some nice shortcuts Resizing Behavior Basic Constraints Use the Auto Layout Issue pane to resolve issues. It looks like this: Tip: Avoid resizing controls, reset to their intrinsic size with Size To Fit.

In code Make sure you set view.translatesautoresizingmaskintoconstraints = NO; Add constraints using either: + (id)constraintwithitem:(id)view1 attribute:(nslayoutattribute)attr1 relatedby:(nslayoutrelation)relation toitem:(id)view2 attribute:(nslayoutattribute)attr2 multiplier:(cgfloat)multiplier constant:(cgfloat)c; or + (NSArray *)constraintswithvisualformat:(nsstring *)format options:(nslayoutformatoptions)opts metrics:(nsdictionary *)metrics views:(nsdictionary *)views; Tip: Use NSDictionaryOfVariableBindings() to create the views dictionary.

Starting a new project with Auto Layout New Xcode projects have Auto Layout turned on by default. Storyboards: create as many constraints as possible in IB Constraints are mutable so hook up IBOutlets to them Interface Builder turns off autoresizing automatically for views created there. Feel free to still opt out of Auto Layout for some views. You re not doing anything wrong.

Converting old projects to Auto Layout Set translatesautoresizingmaskintoconstraints = NO; on views you want to opt into Auto Layout. Only edit the frame on views that are not part of auto layout. Implement + (BOOL)requiresConstraintBasedLayout for custom views. Tip: This Could be painful.

Multiple Screen Size Support Rotation is something we already know how to deal with. Another thing we already do is support ipad and iphone screen sizes. Multiple screen sizes are just a more general case. Tip: You can even use a single storyboard for both ipad and iphone. If you re craaazy!

DEMO

ANIMATING WITH AUTO LAYOUT

Two Options Animate your constraints Some claim it s too slow. Limited on what you can do since it has to be defined as a constraint. Animate with CoreAnimation CoreAnimation layer animations don t invalidate view frames. Feels a bit dirty, like you re two timing Auto Layout.

Animating Constraints Simple once you find your target constraint One easy way is to use outlets. @property IBOutlet NSLayoutConstraint *animatedconstraint; self.animatedconstraint.constant = change; [UIView animatewithduration:0.5f animations:^{ [self.view layoutifneeded]; }];

Animating with CoreAnimation Seems best for temporary flouting of auto layout constraints CABasicAnimation* animation = [CABasicAnimation animationwithkeypath:@ translation"];! animation.duration = 0.5f; animation.autoreverses = YES; animation.tovalue = [NSValue valuewithcatransform3d:catransform3dmaketranslation(100, 100, 0)];! [viewtoanimate.layer addanimation:animation forkey:nil];

Animating Transforms Container View with minimal constraints Can set translatesautoresizingmaskintoconstraints = YES; for views inside this container. Then layout layout frames. CGAffineTransform animationtransform = CGAffineTransformMakeScale(scaleFactor, scalefactor));! [UIView animatewithduration:0.5f animations:^{ viewtotransform.transform = CGAffineTransformConcat(viewToTransform.transform, animationtransform); }];

ANIMATION DEMO

DEBUGGING AUTO LAYOUT

What do I do with those little orange lines in Interface Builder? Auto Layout Issue Navigator Took me forever to find this on my own. It then took me forever to start using the icons on the right. Editor Canvas Show Involved Views For Selected Constraints Editor Canvas Show Intrinsic Size Constraints Contributing To Ambiguity.

Constraints If you see NSLayoutResizingMaskConstraints in the console you probably should turn translatesautoresizingmaskintoconstraints off. Reference Apple s Resolving Issues section of their Auto Layout Programming Guide and look for the problem you re having. Use UIView s constraint debugging methods: - (NSArray *)constraintsaffectinglayoutforaxis:(uilayoutconstraintaxis)axis - (BOOL)hasAmbiguousLayout - (void)exerciseambiguityinlayout

NSLayoutConstraint Add category methods to improve debug output. Justin Williams suggests something like this: #ifdef DEBUG! - (NSString *)constraint_description { NSString *description = [self description];! return [description stringbyappendingformat:@"(%@, %@)", [self.firstitem restorationidentifier], [self.seconditem restorationidentifier]]; } #endif!

DEBUGGING DEMO

THINGS YOU SHOULD KNOW IF YOU RE A BAD-ASS UNICORN

Custom Views Implement -updateconstraints to build constraints for your view s content or - (void)updateviewconstraints at the view controller level. Implement -requiresconstraintbasedlayout if you don t degrade gracefully. Make sure your alignment rect is correct given content ornamentation. If you have text content: - (UIView *)viewforbaselinelayout

Content Size Define your content size with -intrinsiccontentsize You must notify Auto Layout if this changes by calling: -invalidateintrinsiccontentsize Content hugging Content compression resistance

Spacer Views This is the 1x1 transparent gif of Auto Layout Allows for lots of complex layouts. Read Apple s Auto Layout By Example Documentation.

1. Unicorns can be captured only by unfair means, and their single horn is said to neutralize poison. 2. One popular method of hunting unicorns involved entrapment by a virgin. 3. When Marco Polo saw a rhinoceros for the first time, he thought it was a unicorn. -Art credit: Elinor, 5 years old.

Q&A Talk notes: http://nicemohawk.com/talks/auto-layout/

Talk notes: http://nicemohawk.com/talks/auto-layout/ Ben Lachman Nice Mohawk Limited @blach ben@nicemohawk.com

Q&A WHO USES AUTO LAYOUT ALREADY? I WANT A MORE CONVENIENT WAY TO FIDDLE WITH AUTO LAYOUT. CATEGORIES ANYONE? HAS ANYONE INTEGRATED UIDYNAMICS AND AUTO LAYOUT? Talk notes: http://nicemohawk.com/talks/auto-layout/

Talk notes: http://nicemohawk.com/talks/auto-layout/ Ben Lachman Nice Mohawk Limited @blach ben@nicemohawk.com