Monday, 1 November The ios System

Similar documents
Today s Topics. Views Drawing Text & Images Animation

View Hierarchy - UIWindow

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

Announcements. Lab 3. Lab 2 is due on Monday Sept 21 st. Lab 3 is posted Due September 30 th

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

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

CS193p Spring 2010 Monday, April 12, 2010

COMP327 Mobile Computing. Lecture Set 9 - Model, View, Controller

CS193P - Lecture 2. iphone Application Development. Objective-C Foundation Framework

Views. A view (i.e. UIView subclass) represents a rectangular area Defines a coordinate space

CS193P - Lecture 2. iphone Application Development. Objective-C Foundation Framework

iphone OS Overview

Core Graphics & Animation. ios App Development Fall 2010 Lecture 17

Stanford CS193p. Developing Applications for iphone 4, ipod Touch, & ipad Fall Stanford CS193p Fall 2010

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

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

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

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

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

Announcements. Today s Topics

Developing Applications for ios

Collections & Memory Management. Lecture 2

Getting Help. iphone Application Programming Lecture 3: Foundation Classes. Data Structures in Objective C. Online Documentation.

iphone Application Programming Lecture 3: Foundation Classes

ios Mobile Development

Custom Views and Events. Lecture 7

NSObject. - (NSString *)description Provides us with a string description of the object

Mobile Application Development

Graphics and Animation on ios

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

CS193p Spring 2010 Thursday, April 29, 2010

Stanford CS193p. Developing Applications for iphone 4, ipod Touch, & ipad Spring Stanford CS193p Spring 2011

Views, Drawing, and Events. Lecture 5

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

COCOA WORKSHOP PART 1. Andreas Monitzer

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

Core Graphics and OpenGL ES. Dr. Sarah Abraham

epicurious Anatomy of an ios app Robert Tolar Haining June 25, 2010 ConvergeSE

The Best of Both Worlds: Using UIKit with OpenGL

ITP 342 Mobile App Development. Data Persistence

CS193p Spring 2010 Wednesday, March 31, 2010

Contents. iphone Training. Industry Trainers. Classroom Training Online Training ON-DEMAND Training. Read what you need

Collections. Fall, Prof. Massimiliano "Max" Pala

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?

Objective-C Primer. iphone Programmer s Association. Lorenzo Swank September 10, 2008

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

ITP 342 Mobile App Dev. Animation

Assignment II: Foundation Calculator

Custom Views and Drawing. Lecture 5

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

ITP 342 Mobile App Development. Data Persistence

Mobile Application Programing: ios. Messaging

ITP 342 Mobile App Dev. Animation

Introductory ios Development

ITP 342 Mobile App Dev. Animation

CS193E Lecture 7. Document-based Applications NSTableView Key-Value Coding

Mobile Application Programming. Controls

Designing iphone Applications

OVERVIEW. Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net

User Experience: Windows & Views

View Controller Lifecycle

Developing Applications for ios

CS193E Lecture 14. Cocoa Bindings

CUSTOM VIEWS. The View Hierarchy. Chapter 12

Review. iphone Application Programming Lecture 2: Objective-C, Cocoa. History. Objective-C. Device restrictions. Interaction paradigm changes

Getting Help. iphone Application Programming Lecture 3: Foundation Classes. Data Structures in Objective C. Online Documentation.

Praktikum Entwicklung von Mediensystemen mit

Developing Applications for ios

Porting Objective-C to Swift. Richard Ekle

ios Development Lecture 1 Introduction to Objective-C Ing. Simone Cirani

Developing applications for ios

ios: Objective-C Primer

ios Mobile Development

iphone Programming Touch, Sound, and More! Norman McEntire Founder Servin Flashlight CodeTour TouchCount CodeTour

Review. iphone Application Programming Lecture 2: Objective-C, Cocoa. History. Objective-C. Device restrictions. Interaction paradigm changes

Review (Basic Objective-C)

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

Event Delivery: The Responder Chain

Objective-C and COCOA Applications

COMP327 Mobile Computing Session: Tutorial Objective-C and the Foundation Framework

CS193P - Lecture 8. iphone Application Development. Scroll Views & Table Views

CS 47. Beginning iphone Application Development

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

Apple introduced MapKit with ios, maps were based on Google.

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

ITP 342 Mobile App Dev. Data Types

Working Effectively with Objective-C on iphone OS. Blaine Garst Wizard of Runtimes

Apple Development Technology Workshops

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

Building a (Core) Foundation. Rob Napier

Using Swift with Cocoa and Objective-C

ITP 342 Mobile App Dev. Fundamentals

CS193E Lecture 12. Formatters Cocoa Text More View Drawing

SAMPLE CHAPTER. Brendan G. Lim Martin Conte Mac Donell MANNING

Xcode 6 and ios 8 What s New for Software Developers

Building Better Apps with Value Types in Swift Session 414

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

Data Management

Richard Wentk. Cocoa. Developer Reference.

Adopting Advanced Features of the New UI

Transcription:

The ios System

System Overview

System Overview

System Overview

System Overview

System Overview

System Overview

Foundation Classes (Useful)

Foundation Framework Value and collection classes User defaults Archiving Notifications Undo manager Tasks, timers, threads File System, pipes, I/O, bundles

NSObject Root class Introspection Object equality Implements many basics Memory management

NSString General-purpose Unicode string support Unicode coding system Conssitently used throughout Cocoa Touch instead of char / char * Easy to suuport any language

String Constants In C: simple In ObjC @ just as simple Constant string are NSString instances: NSString *string = @ hello 41308

stringwithformat & format String Similar to printf or sprintf with %@ added for objects: NSString astring = @ Dada NSString *log = [ NSString stringwithformat:@ lan mo %@, astring]; Similar to printf or sprintf with %@ added for objects: NSLog(@ lan mo %@ astring);

Other Common NSString methods - (BOOL) isequaltostring:(nsstring*) string; - (BOOL) hasprefix: (NSString*) string; - (int) intvalue; - (double) doublevalue;

NSMutableString NSMutableString - subclasses of NSString Modifiable String +(id) string; -(void)appendstring:(nsstring *)string; -(void)appendformat:(nsstring*)format,...;

Collections Array - ordered collection of objects Common enumeration mechanism Immutable and mutable versions Prevents unexpected changes Dictionary - collection of key-value paris Set - unordered collection of unique objects Immutable collections - share without error Mutable objects carry performance overhead

Common NSArray methods NSArray +arraywithobjects:(id)firstobj,..., nil; -(unsigned)count; -(id)objectatindex:(unsigned)index; -(unsigned)indexofobject:(id)object; NSArray * array = [NSArray arraywithobjects:@ A, B, C, nil); if([array indexofobject:@ D ] == NSNotFound) { NSLog(@ Not Found ); }

NSMutableArray NSMutableArray - subclasses of NSArray Can insert, remove object in an Array +(NSMutableArray *)array; -(void)addobject:(id)object; -(void)removeobject:(id)object; -(void)removeallobjects; -(void)insertobject:(id)object atindex:(unsigned)index;

NSDictionary Common NSDictionary methods + dictionarywithobjecsandkeys: (id)firstobject,...; - (unsigned)count; - (id)objectforkey:(id)key; Return nil if no object found

NSMutableDictionary NSMutableDictionary - subclasses of NSDictionary Can insert, remove object in a NSDictionary +(NSMutableDictionary *)dictionary; -(void)setobject:(id)object forkey:(id)key; -(void)removeobjectforkey:(id)key; -(void)removeallobjects;

Enumeration Consistent way of enumeration over objects in collections. Use with NSArray, Dictionary, NSSet, etc. //old Person *person; int count = [array count]; for(int i =0; i<count; i++) { NSLog([person description]); } //enumeration!!!! for(person *person in array) { NSLog([person description]); }

NSNumber In objc, you can use standard C primitive number NSNumber is used to wrap C number types as object. Subclass of NSValue Number for Collection (Array, Dict...) Common NSNumber methods: +(NSNumber*)numberWithInt:(ind)value; +(NSNumber*)numberWithDouble:(double)value (int) intvalue; (double)doublevalue;

View

View Fundamentals Rectangular area on screen Draw content Handles events (e.g. Touch ) Subclass of UIResponder (event handing class) Views arranged hierarchically every view has one superivew very view has zero or more subviews

UIWindow Views live inside of a window UIWindow is actually jst a view adds some additional functionality specific to top level One UIWindow for an iphone app Contains the entire view hierarchy Set up by default in Xcode template project

View - Manipulation Add /remove views in IB or using UIView methods -(void)addsubview:(uiview *)view; -(void)removefromsuperview; Manipulate the view hierarchy manually: -(void) insertsubview:atindex: -(void) insertsubview:belowsubview: -(void)insertsubview:abovesubview: -(void)exchangesubviewatindex:withsubviewatindex

View-related structures CGPoint location in space: {x, y} CGSize dimension: {width, height} CGRect location and dimension: {origin, size}

View-related structures

View-related structures

Creating view - by IB View is created commonly by Interface Builder Drag out any of existing view objects (button, label and etc) Or drag generic UIView and set customclass

Manual Creation View are initialized using -initwithframe: CGRect frame = CGRectMake(0,0,200,150); UIView *v = [[UIView alloc] initwithframe:frame]; //add subview into window [window addsubview:label];

Defining Custom Views Subclass UIView For custom drawing, you override: -(void)drawrect:(cgrect)rect; For event handling, you override: -(void)touchesbegan:(nsset*)touches withevent:(uievent *)event; -(void)touchesmoved:(nsset*)touches withevent:(uievent *)event; -(void)touchesended:(nsset*)touches withevent:(uievent *)event; -(void)touchescancelled:(nsset*)touches withevent:(uievent *)event;

Try - MoveMe

Animation

UIView Animations UIView supports a number of animatable properties frame, bounds, center, alpha, transform Create blocks around changes to animatable properties Animations run asynchronously and automatically Additional animation options: delay before start start at specific time curve (easing) repeat count autoreverses (e.g. ping pong)

View Animation Example -(void)showadvancedoptions{ //assume polygon view and options view [UIView beginanimations: @ advancedanimations context:nil]; [UIView setanimationduration:0.3]; //make optionsview visible (alpha is currently 0.0) optionsview.alpha = 1.0; //move the polygonview down CGRect polygonframe = polygonview.frame; polygonframe.origin.y += 200; polygonview.frame = polygonframe; } [UIView commitanimations];

UIView animation allow for a delegate -(void)showadvancedoptions{ //assume polygon view and options view [UIView beginanimations: @ advancedanimations context:nil]; [UIView setanimationduration:0.3]; //make optionsview visible (alpha is currently 0.0) optionsview.alpha = 1.0; //move the polygonview down CGRect polygonframe = polygonview.frame; polygonframe.origin.y += 200; polygonview.frame = polygonframe; } [UIView commitanimations];

Drawing Views

-(void)drawrect:(cgrect)rect [UIView drawrect:] does nothing by default If not overridden, the background Color is used to fill Override - drawrect: to draw a custome view rect argument is area to draw drawrect: is invoked automatically When a view needs to be redrawn use: - (void)setneedsdisplay;

CoreGraphics and Quartz 2D UIKit offers basic drawing functions UIRectFill(CGRect rect) & UIRectFrame(CGRect rect) CoreGraphics: Drawing APIs CG is a C-based API (not Objective-C!!!) which offers simple but powerful graphics primitives Graphics context Transformations Paths Colors Fonts and Painting operations

Graphics Contexts All drawing is done into an opaque graphics context Draws to screen, bitmap buffer, printer, PDF, etc Graphics context setup automatically before invoking drawrect defines current path, line width, transform, etc. Access the graphics context within drawrect: Calling (CGContextRef)UIGraphicsGetCurrentContext(void); Use CG calls to change settings Context only valid for current call to drawrect

CG Wrapper Some CG functionality wrapped by UIKit UIColor Convenience for common colors: UIColor *redcolor = [UIColor redcolor]; UIFont Access system font: UIFont *font = [UIFont systemfontsize:14.0];

Simple drawrect: example Draw a solid color and shape -(void)drawrect:(cgrect)rect{ CGRect bounds = [self bounds]; [[UIColor graycolor] set]; UIRectFill(bounds); CGRect sq = CGRectMake(10,10,50,100); [[UIColor redcolor] set]; UIRectFill(sq); } [[UIColor blackcolor] set]; UIRectFrame(sq);

Draw more complex shapes Common steps for drawrect: are Get current graphics context Define a path Set a color Stroke or fill path Repeat, if necessary

Paths & CGPath CoreGraphics paths define shapes Made up of lines, arcs curves and rectangles Creation and drawing of paths are two distinct operation Define path first, then draw it Two parallel sets of functions for using paths

Simple Path Example - (void) draw Rect:(CGRect)rect{ CGContextRef context = UIGraphicsGetCurrentContext(); [[UIColor graycolor set]; UIRectFill([self bounds]); CGContextBeginPath(context); CGContextMoveToPoint(context, 75, 10); CGContextAddLineToPoint(context, 10, 150); CGContextAddLineToPoint(context, 160, 150); CGContextClosePath(context); } [[UIColor redcolor] setfill]; [[UIColor blackcolor] setstroke]; CGContextDrawPath(context, kcgpathfillstroke);