Chapter 8 Vocabulary

Animation – the act of bringing to life.

Basic Animation – animates between a start and end value.

Closure – is a discrete bundle of functionality that can be passed around your code. Functions and methods are a special case of closures.

Anonymously – passing closure directly into the method instead of assigning it to a variable or constant.

Linear– constant speed from beginning to end (.CurveLinear)

Ease-in– accelerating to constant speed and then ending abruptly (.CurveEaseIn)

Ease-out– beginning at full speed and then slowing down at the end (.CurveEaseOut)

Ease-in/Ease-out- (.CurveEaseInOut)

Allow user interaction– by default views cannot be interacted with when animating, this option overrides the default (.AllowUserInteraction)

Repeat– repeats animation indefinitely (.Repeat)

Autoreverse– runs animation forward and backwards and returns initial state (.Autoreverse)

 

Chapter 8 Controlling Animations

Animation – the act of bringing to life.

In the Xcode’s open the help menu and select documentation. Search for UIView Class Reference and scroll to the section titled Animation. This section gives animation recommendations and a list of UIView properties that can be animated.

Basic Animation

Basic Animation – animates between a start and end value.

  • ex/ class func animateWithDuration(duration:NSTimeInterval, animations:() ->Void);
  • This is the simplest UIView animation method. The class takes two arguments duration of type NSTimeInterval (Double) and animation variable for closure.

Closures

Closure – is a discrete bundle of functionality that can be passed around your code. Functions and methods are a special case of closures.

  • allows easy passing of arguments to functions and can be a return type of a function or method

A closure is a comma separated list of arguments with parentheses followed by return arrow and return type.

  • ex/ (arguments) -> return type

This differs from the syntax of a function: func function(arguments) -> return type

Closure signature that animation argument expects, this closure takes in no argument and doesn’t return anything:

class func animateWithDuration(duration:NSTimeInterval, animations:() ->Void);

To declare a closure in code: {(arguments) -> return type in //code }

Anonymously – passing closure directly into the method instead of assigning it to a variable or constant.


Another Label

Add the following lines of code to the ViewController.swift file to add another label to transition to.

screen-shot-2016-10-14-at-11-24-31-am screen-shot-2016-10-14-at-11-24-43-am screen-shot-2016-10-14-at-11-25-12-am


Animation Completion

This can be important if you need to know when an animation is completed. For example if you want to program an animation’s start after another animation ends. To do this a closure will need to be passed for the completion argument. Like so:

screen-shot-2016-10-19-at-1-04-40-pm

Delay indicates how long the system should wait before triggering the animation.


Animation Contraints

Animating constraints involves animating where the object located rather than how the object appears or disappears.

First you need a reference to the constraint to be modified. Declare two outlets for the label’s centering constraints in the ViewController.swift file.

screen-shot-2016-10-19-at-1-04-59-pm

In the Main.storyboard connect the outlets to their constraints.

  • Control + drag from View Controller to Current Question Label.centerX and do the same for Next Question Label.centerX.
  • Delete currentQuestionLabel.
  • Then Control + drag upwards from Next Question button and select Center Horizontally in Container.

To move the constraints from their position implement the following code in the ViewController.swift file.

screen-shot-2016-10-19-at-1-05-20-pm

Each time a constraint is modified, you must ask the system to update the frames. You do this by calling layoutIfNeeded() on a view. Update the following in the ViewController.swift file.

screen-shot-2016-10-19-at-1-07-31-pm

To fix a difficult to see bug add the following to the top of the animateLabelTransitions() method.

//Force any outstanding layout changes to occur

view.layoutIfNeeded()


Timing Functions

By default animations use an ease-in/ease-out timing function. Other options are:

  • Linear– constant speed from beginning to end (.CurveLinear)
  • Ease-in– accelerating to constant speed and then ending abruptly (.CurveEaseIn)
  • Ease-out– beginning at full speed and then slowing down at the end (.CurveEaseOut)
  • Ease-in/Ease-out- (.CurveEaseInOut)
  • Allow user interaction– by default views cannot be interacted with when animating, this option overrides the default (.AllowUserInteraction)
  • Repeat– repeats animation indefinitely (.Repeat)
  • Autoreverse– runs animation forward and backwards and returns initial state (.Autoreverse)
  • there are more options in the Constants section of the UIView Class Reference

Chapter 7: Localization

Internalization (i18n): making sure that cultural information such as language and currency are not hardcoded into the application.

Localization (L10n): The process of providing the appropriate data in the application based on the user’s Language and Region Format settings.


In this chapter NSNumberFormatter and NSNNumber classes were used to internationalize the ConversionViewController.

Formatters

NSNumberFormatter has a locale property which is set to the device’s current locale. Every time NSNumberFormatter is used to create a number, it checks its locale property and sets the format accordingly.

NSLocate knows how different regions display symbols, dates, decimals, and whether they use the metric system.


Base Internationalization

Localization -usually involves either generating multiple copies of resources (images, sound, files) for different regions, languages, and string tables

Main Bundle: is created when you build a target in Xcode. All the resources added to the target are copied to the bundle along with the executable itself.

Localizing a resource puts another copy of the resource in the application bundle and are organized by language-specific directories (lproj)

Base Internalization: Xcode specific feature that simplifies the process of localizing interface files.


Preparation for Localization

Preview Assistant (Opt+Cmd+Return): previews how the interface will look across different screen sizes, orientations, and between different localized languages.

+ sign at the lower left corner allows you to add additional screen sizes to the preview canvas.

Button on the lower right allows you to select a language to preview the interface.

Pseudolanguage: helps internationalize the application before receiving translations for all the strings and assets.

The built in Double-Length Pseudolanguage mimics languages that are more verbose by repeating whatever text string is in the text element.

  • A problem with the Double-Length Pseudolanguage is that the contraints must be adjusted to fit the repeating words.
  1. Select label and add constraints by using Ctr+drag label to the left side of the superview
  2. Select Leading Space to Container Margin in the pop-up
    • direction of the drag determines possible constraints displayed: vertical drag shows vertical constraints, horizontal drag shows horizontal constraints, diagonal drag shows both vertical and horizontal constraints
  3. Ctr+drag label to the right of the superview and select Trailing Space to Container Margin
  4. Select the leading constraint by clicking on the I-bar to the left of the label
  5. Open its attributes inspector and change Relation to Greater Than or Equal and Constant to 0
  6. Repeat for other labels

Chapter 7 vocabulary

Internalization (i18n): making sure that cultural information such as language and currency are not hardcoded into the application.

Localization (L10n): The process of providing the appropriate data in the application based on the user’s Language and Region Format settings.

Main Bundle: is created when you build a target in Xcode. All the resources added to the target are copied to the bundle along with the executable itself.

Base Internalization: simplifies the process of localizing interface files.

Preview Assistant: previews how the interface will look across different screen sizes, orientations, and between different localized languages.

Pseudolanguage: helps internationalize the application before receiving translations for all the strings and assets.

 

Chapter 6: Programmatic Views

Creating a View and Constraints Programmatically

Update WorldTrotter:

  1. Remove view from storyboard so that it can be created programmatically. In Main.storyboard, select map view and delete.
  2. Open MapViewController.swift and override loadView() and create a property for map view. When a view controller is created the property is set to nil.screen-shot-2016-09-30-at-11-57-39-am
  3. Update loadView() to add programmatic constraints to the application.screen-shot-2016-09-30-at-12-16-29-pm

Autoresizing masks: used before auto layout to allow views to scale for different screens at runtime.


Anchors

Anchors: properties of the view that correspond to attributes that you might want to constrain to an anchor on another view.

screen-shot-2016-09-30-at-12-31-55-pm

Common Ancestor: A common view higher up the hierarchy. If a constraint only has a single view then that view is considered the common ancestor.

Layout guides: indicate the extent to which the view controller’s view content will be visible. There are three anchors that can be used to add constraints.

  1. topAnchor
  2. bottomAnchor
  3. heightAnchor

screen-shot-2016-09-30-at-12-47-42-pm

Margins: ensures that the application’s content looks good on different devices by using the margins of the view controller’s view.

screen-shot-2016-09-30-at-12-47-08-pm

Programmatic Controls:

  1. UIControlEvents.TouchDown – a touch down on the control
  2. UIControlEvents.TouchUpInside – a touch down followed by a touch up while still within the bounds of the control
  3. UIControlEvents.ValueChanged – a touch that causes the value of the control to change
  4. UIControlEvents.EditingChanged – a touch that causes an editing change for a UITextField

 

 

Chapter 5: View Controllers

Lazy Loading: when the view controller’s view is not created until it needs to appear on the screen.

Two ways that a view controller can create its view hierarchy:

  1. programmatically, overriding the UIViewController method loadView()
  2. in Interface Builder, by using an interface file such as storyboard

Initial View Controller: acts as an entry point into the storyboard. Each storyboard has exactly one initial view controller.


Add and configure another view controller to the canvas and set it to be the initial view controller for the storyboard.

  1. Open Main.storyboard
  2. From object library, drag a View Controller onto the canvas
    • The view controller should display an MKMapView-class designed to display a map-instead of the white UIView.
  3. Select the view of the View Controller and press delete to remove the view from the canvas.
  4. Drag a Map Kit View  from the object library  onto the view controller to set it as the view for this view controller.
  5. Select View Controller and open its attributes inspector.
  6. Under the View Controller section, check the box next to “Is Initial View Controller.”
    • The gray arrow indicated the initial view controller.

Framework – a share library of code that includes associated resources such as interface files and images.

  • ex: import UIKit
  • if you include a framework using the import keyword without using any code that uses the framework, the compiler will optimize it out.

Manually link MapKit framework for MKMapView to work:

  1. With the project navigator open, click on WorldTrotter project and open project settings.
  2. Find and open general tab in the settings.
  3. Find section labeled “Linked Frameworks and Libraries.”
  4. Click on the “+” symbol and search MapKit.framework.
  5. Select the framework and click add.

UIWindow has a rootViewController property- when a view controller is set as the window’s rootViewController, the view gets added to the window’s view hierarchy. When the property is set an existing subviews on the window are removed and the view controller’s view gets added to the window with the appropriate Auto Layer constraints.

Main Interface: reference to a storyboard. Each application has one main interface and gets set in the project settings.

When the application launches, the initial view controller for the main interface gets set at the rootViewController of the window.


Tab Bar

UITabBarController keeps an array of view controllers and maintains a tab bar.

  1. Open Main.storyboard and select View Controller.
  2. From the Editor menu, choose Embed In -> Tab Bar Controller.
  3. Add the Conversion View Controller to the Tab Bar Controller’s view hierarchy
  4. Control + drag from Tab Bar Controller to the Conversion View Controller.
  5. From Relationship Segue section, choose view controller.
  6. Build + Run

Each tab on the tab bar can display a title and an image.

  • ex/ The favorite, recent, contacts, keyboard, and voicemail tabs on an iPhone.

Adding Images

  1. In project navigator, open Asset Catalog (open Assets.xcassets).
  2. Drag images into the images set list on the left of the Asset Catalog. Can be set programmatically or in a storyboard.
  3. In Main.storyboard, locate the View Controller. Select the tab bar item and open attributes inspector.
  4. Under Bar Item, change “Title” to “Map” and choose MapIcon from Image menu.
  5. Build + Run

https://iosappdevelopment.chelseairizarry.org/vocabulary/chapter-5-vocabulary/