ITP 342 Mobile App Dev. Animation

Similar documents
ITP 342 Mobile App Dev. Animation

ITP 342 Mobile App Dev. Animation

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

Mobile Development Lab 3

lecture 10 UI/UX and Programmatic Design cs : spring 2018

Enhancing your apps for the next dimension of touch

Event Delivery: The Responder Chain

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

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

ITP 342 Mobile App Dev. Connections

AVAudioRecorder & System Sound Services

Monday, 1 November The ios System

ITP 342 Mobile App Dev. Interface Fun

Media Playback and Recording. CS193W - Spring Lecture 3

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

Praktikum Entwicklung von Mediensystemen mit

Gestures. Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder

ITP 342 Mobile App Dev. Interface Components

ITP 342 Mobile App Dev. Web View

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

App. Chapter 19 App. App (ViewController) App. Single View Application Single View Application View. (View Controller)

Cocoa Touch Best Practices

CSC 581: Mobile App Development Spring 2019

ITP 342 Mobile App Dev

Topics in Mobile Computing

ITP 342 Mobile App Dev. Connections

Announcements. Today s Topics

ITP 342 Mobile App Dev. Interface Builder in Xcode

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

Announcements. Lab 2 is due next Monday (Sept 25 th ) by 11:59 PM. Late policy is 10% of lab total per day late. So -7.5 points per day late for lab 2

Titanium.UI.View Class API

Types And Categories. Anat Gilboa

Stream iphone Sensor Data to Adafruit IO

Implementing UI Designs in Interface Builder

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

EXERCISES RELATED TO ios PROGRAMMING

COMP327 Mobile Computing Session:

ios Application Development Lecture 5: Protocols, Extensions,TabBar an Scroll Views

Mysteries of Auto Layout, Part 1

Questions. Exams: no. Get by without own Mac? Why ios? ios vs Android restrictions. Selling in App store how hard to publish? Future of Objective-C?

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

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

Developing Applications for ios

ios Mobile Development

iphone Application Programming Lecture 5: View Programming

Every language has its own scoping rules. For example, what is the scope of variable j in this Java program?

View Controller Advancements for ios8

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

Exercise NMCGJ: Animated Graphics

let w = UIWindow(frame: UIScreen.mainScreen().bounds)

CSC 581: Mobile App Development Spring 2018

Stanford CS193p. Developing Applications for ios. Winter CS193p! Winter 2015

Gerontechnology II. Collecting Smart Phone Sensor Data for Gerontechnology. Using ios

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

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

Advanced Scrollviews and Touch Handling Techniques

ios 12 App Development Essentials

Mobile Application Programing: ios. Messaging

ITP 342 Mobile App Dev. Fundamentals

A Mad Libs app that you will navigate through 3 UIViewControllers to add text that will be shown in a story on the fourth UIViewController.

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues

Tables. Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder

SWIFT & #IOExtendedCLT, 18th May 2016

UI Design and Storyboarding

Getting to Know Keynote on ipad

Integrating Game Center into a BuzzTouch 1.5 app

Mastering UIKit on tvos

ios Memory Deep Dive #WWDC18 Kyle Howarth, Software Engineer James Snee, Software Engineer Kris Markel, Software Engineer

ios Development - Xcode IDE

Table of Contents. ios Spellbook

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

Key Value Observing (KVO) CPRE 388

Graphics and Animation

Optimizing Swift Performance Session 409

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

Mobile Development - Lab 2

ios 9 Day by Day Also by shinobicontrols This version was published Scott Logic Ltd

ios 11 App Development Essentials

Xcode & Swift: Introduction

Building the App - Part 5 - Adding a Link

ITP 342 Mobile App Dev. Functions

ITP 342 Mobile App Dev. Table Views

Stanford CS193p. Developing Applications for ios. Winter CS193p! Winter 2015

Below are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones.

AdFalcon ios SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

Contents. Orientation SearchBar and Gallery List Advanced Multiple Form Multi Touch Animations Layout Designing UI using UI Builder

April 2 to April 4, 2018

Note: To record with the ios App your Panopto server must be 4.3 or higher.

What's New in UIKit Dynamics and Visual Effects Session 229

ITP 342 Mobile App Dev. Table Views

User Interfaces. Lecture 15. Application Programming on Mac OS. Hamza Bennani September 4, 2018

CONTENTS. Working With Feeds Viewing Your Feeds Working With Snippets Deleting Snippets Rev AA

Assignment III: Graphing Calculator

} override func didreceivememorywarning() { 26 super.didreceivememorywarning() 27 } 28 } Pause Stop

DART SVP. Software Manual For Web Based User Interface And For Apple ipod touch User Interface. Software Version 3.0.x ipod Application Version 1.

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

ADVANCED M A. Learn SiriKit, imessage apps, rich notifications, and more. with real-world projects HACKING WITH SWIFT COMPLETE TUTORIAL COURSE

User Experience: Windows & Views

Widget Tour. iphone and ipod touch Development Fall 2009 Lecture 7

Assignment III: Graphing Calculator

Transcription:

ITP 342 Mobile App Dev Animation

Views Views are the fundamental building blocks of your app's user interface, and the UIView class defines the behaviors that are common to all views. Responsibilities Drawing and animation Layout and subview management Event handling

Drawing and Animation Views draw content in their rectangular area using UIKit or Core Graphics Some view properties can be animated to new values. 3

Animations The following properties of the UIView class are animatable: frame bounds center transform alpha backgroundcolor 4

Animations To animate your changes, create a UIViewPropertyAnimator object and use its handler block to change the values of your view's properties. The UIViewPropertyAnimator class lets you specify the duration and timing of your animations, but it performs the actual animations. You can pause a property-based animator that is currently running to interrupt the animation and drive it interactively. 5

Animator An animator is always in one of the following states: Inactive: This is the initial state. As an animation finishes, this will also be the state it returns to. Active: The animator becomes active as soon as you call startanimation() or pauseanimation(). It will stay in this state until the animations finishes naturally or the stopanimation() method gets called. Stopped: The animator enter this state after calling stopanimation(). 6

Animator 7

UIViewPropertyAnimator When creating a property animator object, you specify the following: A block containing code that modifies the properties of one or more views. The timing curve that defines the speed of the animation over the course of its run. The duration (in seconds) of the animation. An optional completion block to execute when the animations finish. 8

Working with Closures Closures allow you to create distinct segments of code that can be passed around to methods or functions as if they were values. Closures are Swift objects, which means they can be added to collections like Array or Dictionary. They also have the ability to capture values from the enclosing scope, making them similar to blocks or lambdas in other programming languages. 9

Example In a method such as an IBAction, create an animator and then start the animation let animator = UIViewPropertyAnimator(duration: 10, curve: UIViewAnimationCurve.easeInOut) { self.view.backgroundcolor = newcolor animator.startanimation() 10

Example Example where you call another method in the closure for the animation func fadeoutlabel() { msglabel.alpha = 0 @IBAction func swipedright(_ sender: UISwipeGestureRecognizer) { msglabel.alpha = 1 msglabel.text = "Swiped Right" let animator = UIViewPropertyAnimator(duration: 5, curve: UIViewAnimationCurve.linear, animations: {() in self.fadeoutlabel() ) animator.startanimation() 11

Example Example where you use the name of the method func fadeinlabel() { msglabel.alpha = 1 @IBAction func swipedleft(_ sender: UISwipeGestureRecognizer) { msglabel.alpha = 0 msglabel.text = "Swiped Left" let animator = UIViewPropertyAnimator(duration: 5, curve: UIViewAnimationCurve.linear, animations: fadeinlabel) animator.startanimation() 12

Example Add Completion Fade out current text, update text, and fade in func fadeoutlabel() { msglabel.alpha = 0 @IBAction func doubletapped(_ sender: UITapGestureRecognizer) { let firstanimator = UIViewPropertyAnimator(duration: 5, curve:.linear, animations: fadeoutlabel) firstanimator.addcompletion { (position) in self.msglabel.text = "Double Tapped" let animator = UIViewPropertyAnimator(duration: 5, curve: UIViewAnimationCurve.linear, animations: {() in self.fadeinlabel() ) animator.startanimation() firstanimator.startanimation() 13

Previous Way to Animate The following slides use UIView's static animate methods 14

Animate Animate changes to one or more views using the specified duration. class func animate(withduration duration: TimeInterval, animations: @escaping () -> Void) Parameters duration: The total duration of the animations, measured in seconds. If you specify a negative value or 0, the changes are made without animating them. animations: A closure containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This closure takes no parameters and has no return value. This parameter must not be NULL. 15

Example 1 Animation In the ViewController, create a method that passes in a new name (as a String) and fades it in. 16

Example 1 Animation func fadeinstudent(name: String){ // Alpha = 0 means the text is transparent self.namelabel.alpha = 0 self.namelabel.text = name UIView.animate(withDuration: 1.0) { // Fade in the text of the label self.namelabel.alpha = 1 17

What we have: Animate The old string disappears and the new string fades in. What we want: We want the old string to fade out first. We need 2 animations First one to fade out old string Second one to fade in new string after the first one finishes 18

Animate Animate changes to one or more views using the specified duration and completion handler. class func animate(withduration duration: TimeInterval, animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) Parameters duration: The total duration of the animations, measured in seconds. animations: A closure containing the changes to commit to the views. completion: A closure to be executed when the animation sequence ends. This closure has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. 19

Example 2 Animations Create a method that fades in the new text. Create a method that fades out the old text of the label. In the completion argument for the animation, call the method that fades in the new text. 20

Example 2 Animations Create a method that fades in the new text. func animatestudent(name: String){ self.namelabel.text = name UIView.animate(withDuration: 1.0) { self.namelabel.alpha = 1 21

Example 2 Animations Create a method that fades out the old text of the label. In the completion argument for the animation, call the method that fades in the new text. 22

Example 2 Animations func displaystudent(name: String){ UIView.animate(withDuration: 1.0, animations: { // Fade out old text of label self.namelabel.alpha = 0 ) { (finished) in // Upon completion, call animatestudent self.animatestudent(name: name) 23

Example Colors Add code to rotate between 2 colors func animatestudent(name: String){ self.namelabel.text = name // If black, set to USC cardinal red if self.namelabel.textcolor == UIColor.black { self.namelabel.textcolor = UIColor(red: 153.0/255.0, green: 0.0, blue: 0.0, alpha: 1.0) else { self.namelabel.textcolor = UIColor.black UIView.animate(withDuration: 1.0) { self.namelabel.alpha = 1.0 24

Auto Layout & Animation If you are using Auto Layout, then some attributes will not animate such position and size. To turn off Auto Layout 25

Resources Apple's Developer Site: https://developer.apple.com/library/ios/document ation/windowsviews/conceptual/viewpg_iphoneo s/animatingviews/animatingviews.html ios Animation Tutorial: https://www.raywenderlich.com/113674/iosanimation-tutorial-getting-started 26