EEC-492/693/793 iPhone Application Development

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
IOS – Views and Drawing CS4521. Views Rectangular area on screen Draws content Handles events Subclass of UIResponder (event handling class) Views arranged.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
User Interface Programming in C#: Graphics
The Accelerometer CSE 391 Fall 2011 Tony Scarlatos.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Other Input Methods Pre-Lab Lecture 4 1. Revisit 2  Pre-Lab 3 – Animation  Boundary Information  Layer Concept  Animation algorithm  Next Position.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
1 L38 Graphics and Java 2D™ (3). 2 OBJECTIVES In this chapter you will learn:  To understand graphics contexts and graphics objects.  To understand.
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
Custom Views, Drawing, Styles, Themes, ViewProperties, Animations, oh my!
GAO YUAN We are here for:  We know iPhone from iOS Human Interface Guidelines  The guidelines and principles that help you.
Pygame Dick Steflik.
Data-Driven Inference of API Mappings Department of Computer Science Rutgers University Amruta Gokhale- Daeyoung Kim-
Draw Shapes Introduction to simple graphics. What is a Component? A class that resides in the java.awt package Examples include: –Button, java.awt.Button.
1 Windows Graphics. 2 Objectives You will be able to Use the Windows GDI+ to draw arbitrary figures and text on a Windows form. Add a handler for the.
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
Graphics and Multimedia Part #2
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Advanced User Interfaces with Java SD’98 - Session 3206 Ted Faison Faison Computing Inc.
© 2011 Delmar, Cengage Learning Chapter 1 Getting to Know Illustrator.
GDI+ 1. Objectives 2 GDI+ class  Create and render Graphic  Display information on the computer screen, printer 3.
Chapter 6 Working with Patterns and Brushes. Objectives Use the Move command Create a pattern Design a repeating pattern Use the Pattern Options panel.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
Exploring the Macromedia Flash Workspace – Lesson 2 1 Exploring the Macromedia Flash Workspace Lesson 2.
ROOT’s graphics on iOS. ROOT’s graphics (general scheme):
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
User Interface Objects From Beginning iPhone 4 Development and The iPhone Developer’s Cookbook (Chapter 4)
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software
© 2010 Delmar, Cengage Learning Chapter 1 Getting Started with Illustrator.
V 1.0 Programming III. Graphical possibilities Simple graphics (shapes)
Graphics in Android 1 CS7030: Mobile App Development.
Resources & Bitmaps Adding clip art to your application.
2/20/2016 EEC492/693/793 - iPhone Application Development 12/20/2016 EEC492/693/793 - iPhone Application Development 1 EEC-492/693/793 iPhone Application.
Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc.
Notices Assn 4 posted. Due last day of class. Note that Exercise 10 contains the JavaFX code for three simple GUI programs. Winter 2016CMPE212 - Prof.
Intro to Pygame Lecture 05. What is Pygame? It is a set of Python modules designed for writing games. It makes writing games possible for beginners. import.
이미지 뷰의 애니메이션 이미지 뷰는 자체적으로 애니메이션 기능을 제공하고 있습니다.
Adobe Illustrator CS Design Professional WITH ILLUSTRATOR GETTING STARTED.
Lecture 6: Thread Safe Event services and Coordinate System CSS290: APPS ON MOBILE DEVICES.
Advanced AWT The Rendering Pipeline
12 Graphics and Java 2D™.
Drawing And Animations
Android Application 2D Graphics cs.
Flash Interface, Commands and Functions
Adobe Flash Professional CS5 – Illustrated
Graphics and Multimedia
EEC-492/693/793 iPhone Application Development
ISC440: Web Programming II Ch14: HTML5 Canvas
Java Graphics The basic rendering mechanism is the drawing system that controls when and how programs can draw on a graphics component. When a component.
EEC-492/693/793 iPhone Application Development
Graphics in Android Fall 2012 CS2302: Programming Principles.
EEC-492/693/793 iPhone Application Development
CS371m - Mobile Computing Responsiveness.
EEC-492/693/793 iPhone Application Development
Otasuke GP-EX! Chapter 1 Menu Screen.
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
CSS290: Apps on Mobile Devices
Presentation transcript:

EEC-492/693/793 iPhone Application Development Lecture 18 Wenbing Zhao & Nigamanth Sridhar 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Outline Accelerometer Core Graphic and Quartz 2D Assignment: Build the Ball app in chapter 15 Challenge: add the touch feature Build the Draw app for CG drawing 11/28/2018 EEC492/693/793 - iPhone Application Development

What Are Accelerometers? Measure changes in force Y direction: opposite of coordinate system 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Kinds of Orientation Physical orientation How is the device positioned? Interface orientation Where is the status bar? 11/28/2018 EEC492/693/793 - iPhone Application Development

Getting the Physical Orientation UIDevice class Start notifications beginGeneratingDeviceOrientationNotifications Get Orientation // delivered to registered observers UIDeviceOrientationDidChangeNotification orientation property Stop notifications endGeneratingDeviceOrientationNotifications 11/28/2018 EEC492/693/793 - iPhone Application Development

Getting the Interface Orientation UIApplication class statusBarOrientation property Defines interface orientation, not device orientation UIViewController class interfaceOrientation property - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Shake Detection UIEvent type @property(readonly) UIEventType type; @property(readonly) UIEventSubtype subtype; UIEventTypeMotion UIEventSubtypeMotionShake - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event; - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event; - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {   if (event.type == UIEventSubtypeMotionShake) {     //Your code here   } } 11/28/2018 EEC492/693/793 - iPhone Application Development

Getting the Raw Accelerometer Data Part of the UIKit framework Delivers 3-axis data Configurable update frequency (approx 10–100Hz) Delegate-based event delivery Classes UIAccelerometer UIAcceleration Protocol UIAccelerometerDelegate 11/28/2018 EEC492/693/793 - iPhone Application Development

Configuring the Accelerometer: Starting the event delivery - (void)enableAccelerometerEvents { UIAccelerometer* theAccel = [UIAccelerometer sharedAccelerometer]; theAccel.updateInterval = 1/50; // 50 Hz theAccel.delegate = self; } Event delivery begins as soon as you assign the delegate 11/28/2018 EEC492/693/793 - iPhone Application Development

Defining Your Delegate Object: Processing the accelerometer data - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration { // Get the event data UIAccelerationValue x, y, z; x = acceleration.x; y = acceleration.y; z = acceleration.z; // Process the data... } Only one delegate per application Delivered asynchronously to main thread 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Configuring the Accelerometer: Choosing an appropriate update frequency System range is approximately 10–100Hz Frequency should be based on need Determine the minimum frequency for your needs Don’t update too frequently Target ranges Game input: 30–60 Hz Orientation detection: 10–20 Hz 11/28/2018 EEC492/693/793 - iPhone Application Development

Disabling Event Delivery: Stopping the event delivery - (void)disableAccelerometerEvents { UIAccelerometer* theAccel = [UIAccelerometer sharedAccelerometer]; theAccel.delegate = nil; } 11/28/2018 EEC492/693/793 - iPhone Application Development

CoreGraphics and Quartz 2D UIKit offers very basic drawing functionality UIRectFill(CGRect rect); UIRectFrame(CGRect rect); CoreGraphics: Drawing APIs CG is a C-based API, not Objective-C CG and Quartz 2D drawing engine define simple but powerful graphics primitives Graphics context Transformations Paths Colors Fonts Painting operations 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development 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: by calling (CGContextRef)UIGraphicsGetCurrentContext(void); Use CG calls to change settings Context only valid for current call to drawRect: Do not cache a CGContext! 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development CG Wrappers UIColor Convenience for common colors Easily set the fill and/or stroke colors when drawing UIColor *redColor = [UIColor redColor]; [redColor set]; // drawing will be done in red UIFont Access system font Get font by name UIFont *font = [UIFont systemFontOfSize:14.0]; [myLabel setFont:font]; 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Drawing Custom Views - (void)drawRect:(CGRect)rect -[UIView drawRect:] does nothing by default If not overridden, then backgroundColor is used to fill Override - drawRect: to draw a custom view rect argument is area to draw Should never call drawRect: directly Call –(void)setNeedsDisplay instead! 11/28/2018 EEC492/693/793 - iPhone Application Development

Simple drawRect: Example Draw a solid color and shape - (void)drawRect:(CGRect)rect { CGRect bounds = [self bounds]; [[UIColor grayColor] set]; UIRectFill (bounds); CGRect square = CGRectMake (10, 10, 50, 100); [[UIColor redColor] set]; UIRectFill (square); [[UIColor blackColor] set]; UIRectFrame (square); } 11/28/2018 EEC492/693/793 - iPhone Application Development

Drawing 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 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development CGPath CoreGraphics paths define shapes Made up of lines, arcs, curves and rectangles Creation and drawing of paths are two distinct operations Define path first, then draw it CGContext CGPath CGContextMoveToPoint CGPathMoveToPoint CGContextAddLineToPoint CGPathAddLineToPoint CGContextAddArcToPoint CGPathAddArcToPoint CGContextClosePath CGPathCloseSubPath 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Path Example - (void)drawRect:(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); } 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Drawing Text & Images You can draw UIImages in -drawRect: - [UIImage drawAtPoint:(CGPoint)point] - [UIImage drawInRect:(CGRect)rect] - [UIImage drawAsPatternInRect:(CGRect)rect] You can draw NSString in -drawRect: - [NSString drawAtPoint:(CGPoint)point withFont:(UIFont *)font] 11/28/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Build Two Apps 11/28/2018 EEC492/693/793 - iPhone Application Development