The document discusses a lecture on iPhone application development that covers views, drawing, and animation. It provides information on views including view fundamentals, the view hierarchy, view structures like frames and bounds, and creating and manipulating views. It also discusses drawing in views by overriding the drawRect method and using Core Graphics for drawing operations.
Cómo integrar AngularJS con una instalación de Drupal 7 a través de views y services o cómo agregarle a una web estándar las características de una aplicación HTML5.
This presentation reviews the various approaches you can take to creating animations in your iOS apps.
It discusses UIKit animations, including curling pages up (as in the Maps app), flipping back and forth (as in the Stocks app) and image view animations.
It also describes Core Animation, including its implicit animations that occur when you change the value of certain animatable properties, as well as how to create explicit animations.
Cómo integrar AngularJS con una instalación de Drupal 7 a través de views y services o cómo agregarle a una web estándar las características de una aplicación HTML5.
This presentation reviews the various approaches you can take to creating animations in your iOS apps.
It discusses UIKit animations, including curling pages up (as in the Maps app), flipping back and forth (as in the Stocks app) and image view animations.
It also describes Core Animation, including its implicit animations that occur when you change the value of certain animatable properties, as well as how to create explicit animations.
Some basic information and concepts about designing user interface on iOS and Android.
Help designers to quickly have knowledge about how to start and what to prepare when designing app interface on iOS and Android.
Beginning Real World iOS App DevelopmentAndri Yadi
The slide I presented during 1 day training for beginning real world iOS app development on April 7, 2015.
Event details:
http://bit.ly/belajarswift
https://procodecg.wordpress.com/2015/04/07/ios-app-development-training-with-dycode/
Designing the foundations of an iOS application is important to reduce the cost of maintenance and evolution. In this session we will see some best practices on how to organize iOS apps both from the point of view of the Xcode project and the source code. Based on the typical iOS client/server application, we will see how to structure the layers ranging from the user interface to the netwrok layer.
Slides presented at #Pragma Conference 2013
http://pragmamark.org/eventi/pragma-conference-2013/
http://pragmamark.org/sessioni/pragma-conference-2013-building-ios-app-project-and-architecture/
Top iOS App Development Companies | Mobile App Development Companies - 2017Jane Brewer
Top Mobile App Development Companies 2017 | iOS App Developers (iPhone, iPad)
iOS app development is all about idea and implementation. If you are ready to transform your iOS app idea into reality, everything boils down to selecting top iPhone app Development Company.
According to Statista, on average, there are more than 30 thousand new apps submitted to the iTunes App store alone each month and still more written for competing platforms such as Android and Windows. By mid 2016, around 130 billion apps had been downloaded from the Apple App store worldwide. Remember, in order to gain market traction, partnering with reliable mobile app development company will help you scale new heights and minimize loss of resources.
Here you can find the list of top and award-winning mobile app development companies providing innovative iOS solutions.
Designing the foundations of an iOS application is important to reduce the cost of maintenance and evolution. In this session we will see some best practices on how to organize iOS apps both from the point of view of the Xcode project and the source code. Based on the typical iOS client/server application, we will see how to structure the layers ranging from the user interface to the netwrok layer.
Some basic information and concepts about designing user interface on iOS and Android.
Help designers to quickly have knowledge about how to start and what to prepare when designing app interface on iOS and Android.
Beginning Real World iOS App DevelopmentAndri Yadi
The slide I presented during 1 day training for beginning real world iOS app development on April 7, 2015.
Event details:
http://bit.ly/belajarswift
https://procodecg.wordpress.com/2015/04/07/ios-app-development-training-with-dycode/
Designing the foundations of an iOS application is important to reduce the cost of maintenance and evolution. In this session we will see some best practices on how to organize iOS apps both from the point of view of the Xcode project and the source code. Based on the typical iOS client/server application, we will see how to structure the layers ranging from the user interface to the netwrok layer.
Slides presented at #Pragma Conference 2013
http://pragmamark.org/eventi/pragma-conference-2013/
http://pragmamark.org/sessioni/pragma-conference-2013-building-ios-app-project-and-architecture/
Top iOS App Development Companies | Mobile App Development Companies - 2017Jane Brewer
Top Mobile App Development Companies 2017 | iOS App Developers (iPhone, iPad)
iOS app development is all about idea and implementation. If you are ready to transform your iOS app idea into reality, everything boils down to selecting top iPhone app Development Company.
According to Statista, on average, there are more than 30 thousand new apps submitted to the iTunes App store alone each month and still more written for competing platforms such as Android and Windows. By mid 2016, around 130 billion apps had been downloaded from the Apple App store worldwide. Remember, in order to gain market traction, partnering with reliable mobile app development company will help you scale new heights and minimize loss of resources.
Here you can find the list of top and award-winning mobile app development companies providing innovative iOS solutions.
Designing the foundations of an iOS application is important to reduce the cost of maintenance and evolution. In this session we will see some best practices on how to organize iOS apps both from the point of view of the Xcode project and the source code. Based on the typical iOS client/server application, we will see how to structure the layers ranging from the user interface to the netwrok layer.
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024Neo4j
Neha Bajwa, Vice President of Product Marketing, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
UiPath Test Automation using UiPath Test Suite series, part 5DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 5. In this session, we will cover CI/CD with devops.
Topics covered:
CI/CD with in UiPath
End-to-end overview of CI/CD pipeline with Azure devops
Speaker:
Lyndsey Byblow, Test Suite Sales Engineer @ UiPath, Inc.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Elevating Tactical DDD Patterns Through Object Calisthenics
05 Views
1. CS193P - Lecture 5
iPhone Application Development
Views
Drawing
Animation
Tuesday, January 19, 2010 1
2. Announcements
• Assignment 1 grades are out. Contact Paul or Dave if you didn’t
get yours
• Contact Paul or Dave if you need a loaner iPod Touch
• Assignments 2A and 2B due Wednesday, 1/20
Tuesday, January 19, 2010 2
3. Questions from Monday?
• Model, View, Controller
• Interface Builder & Nibs
• Delegate
■ Allows one object to act on behalf of another object
• Target-Action
Tuesday, January 19, 2010 3
4. Today’s Topics
• Views
• Drawing
• Text & Images
• Animation
Tuesday, January 19, 2010 4
6. View Fundamentals
• Rectangular area on screen
• Draws content
• Handles events
• Subclass of UIResponder (event handling class)
• Views arranged hierarchically
■ every view has one superview
■ every view has zero or more subviews
Tuesday, January 19, 2010 6
7. View Hierarchy - UIWindow
• Views live inside of a window
• UIWindow is actually just a view
■ adds some additional functionality specific to top level view
• One UIWindow for an iPhone app
■ Contains the entire view hierarchy
■ Set up by default in Xcode template project
Tuesday, January 19, 2010 7
8. View Hierarchy - Manipulation
• Add/remove views in IB or using UIView methods
- (void)addSubview:(UIView *)view;
- (void)removeFromSuperview;
• Manipulate the view hierarchy manually:
- (void)insertSubview:(UIView *)view atIndex:(int)index;
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)view;
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)view;
- (void)exchangeSubviewAtIndex:(int)index
withSubviewAtIndex:(int)otherIndex;
Tuesday, January 19, 2010 8
9. View Hierarchy - Ownership
• Superviews retain their subviews
• Not uncommon for views to only be retained by superview
■ Be careful when removing!
■ Retain subview before removing if you want to reuse it
• Views can be temporarily hidden
theView.hidden = YES;
Tuesday, January 19, 2010 9
10. View-related Structures
• CGPoint
■ location in space: { x , y }
• CGSize
■ dimensions: { width , height }
• CGRect
■ location and dimension: { origin , size }
Tuesday, January 19, 2010 10
11. Rects, Points and Sizes
CGRect (0, 0) x
54
origin CGPoint
x 80 80
size
y 54
y
144
CGSize
width 144
72
height 72
Tuesday, January 19, 2010 11
12. View-related Structure
Creation Function Example
CGPoint point = CGPointMake (100.0, 200.0);
CGPointMake (x, y) point.x = 300.0;
point.y = 30.0;
CGSize size = CGSizeMake (42.0, 11.0);
CGSizeMake (width, height) size.width = 100.0;
size.height = 72.0;
CGRect rect = CGRectMake (100.0, 200.0,
CGRectMake (x, y, 42.0, 11.0);
width, height) rect.origin.x = 0.0;
rect.size.width = 50.0;
Tuesday, January 19, 2010 12
13. UIView Coordinate System
■ Origin in upper left corner
■ y axis grows downwards
0, 0
+x
+y
Tuesday, January 19, 2010 13
14. UIView Coordinate System
■ Origin in upper left corner
■ y axis grows downwards
0, 0
+x
UIView
+y
Tuesday, January 19, 2010 13
15. Location and Size
• View’s location and size expressed in two ways
■ Frame is in superview’s coordinate system
■ Bounds is in local coordinate system
Tuesday, January 19, 2010 14
16. Location and Size
• View’s location and size expressed in two ways
■ Frame is in superview’s coordinate system
■ Bounds is in local coordinate system
View A
Tuesday, January 19, 2010 14
17. Location and Size
• View’s location and size expressed in two ways
■ Frame is in superview’s coordinate system
■ Bounds is in local coordinate system
0, 0 550
View A
400
Tuesday, January 19, 2010 14
18. Location and Size
• View’s location and size expressed in two ways
■ Frame is in superview’s coordinate system
■ Bounds is in local coordinate system
0, 0 550
View A frame:
View A origin: 0, 0
size: 550 x 400
View A bounds:
origin: 0, 0
size: 550 x 400
400
Tuesday, January 19, 2010 14
19. Location and Size
• View’s location and size expressed in two ways
■ Frame is in superview’s coordinate system
■ Bounds is in local coordinate system
0, 0 550
View A frame:
View A origin: 0, 0
size: 550 x 400
View A bounds:
View B origin: 0, 0
size: 550 x 400
400
Tuesday, January 19, 2010 14
20. Location and Size
• View’s location and size expressed in two ways
■ Frame is in superview’s coordinate system
■ Bounds is in local coordinate system
0, 0 550
View A frame:
View A origin: 0, 0
size: 550 x 400
200, 100
View A bounds:
View B origin: 0, 0
size: 550 x 400
400
Tuesday, January 19, 2010 14
21. Location and Size
• View’s location and size expressed in two ways
■ Frame is in superview’s coordinate system
■ Bounds is in local coordinate system
0, 0 550
View A frame:
View A origin: 0, 0
size: 550 x 400
200, 100 200
View A bounds:
View B origin: 0, 0
size: 550 x 400
400 250
Tuesday, January 19, 2010 14
22. Location and Size
• View’s location and size expressed in two ways
■ Frame is in superview’s coordinate system
■ Bounds is in local coordinate system
0, 0 550
View A frame:
View A origin: 0, 0
size: 550 x 400
200, 100 200
View A bounds:
View B origin: 0, 0
size: 550 x 400
400 250
View B frame:
origin: 200, 100
size: 200 x 250
Tuesday, January 19, 2010 14
23. Location and Size
• View’s location and size expressed in two ways
■ Frame is in superview’s coordinate system
■ Bounds is in local coordinate system
0, 0 550
View A frame:
View A origin: 0, 0
size: 550 x 400
200, 100 200
0, 0 View A bounds:
View B origin: 0, 0
size: 550 x 400
400 250
View B frame:
origin: 200, 100
size: 200 x 250
Tuesday, January 19, 2010 14
24. Location and Size
• View’s location and size expressed in two ways
■ Frame is in superview’s coordinate system
■ Bounds is in local coordinate system
0, 0 550
View A frame:
View A origin: 0, 0
size: 550 x 400
200, 100 200
0, 0 View A bounds:
View B origin: 0, 0
size: 550 x 400
400 250
View B frame:
origin: 200, 100
size: 200 x 250
View B bounds:
origin: 0, 0
size: 200 x 250
Tuesday, January 19, 2010 14
25. Frame is Computed
200, 100 View A
200
View B
250
Tuesday, January 19, 2010 15
26. Bounds
View A
200
0, 0 View B
250
Tuesday, January 19, 2010 16
27. Center
View A
200
0, 0 View B
250
Tuesday, January 19, 2010 17
28. Center
View A
200
300, 225 0, 0 View B
250
Tuesday, January 19, 2010 17
29. Frame
200, 100 View A
200
300, 225 View B
250
Tuesday, January 19, 2010 18
30. Transform
• 45° Rotation
View A
0,
0
300, 225
20 Vi
25
0 ew
0
B
Tuesday, January 19, 2010 19
31. Frame
• The smallest rectangle in the superview’s coordinate system
that fully encompasses the view itself
140, 65 320 View A
0,
0
300, 225
20 Vi
25
0 ew
0
320
B
Tuesday, January 19, 2010 20
32. Frame and Bounds
• Which to use?
■ Usually depends on the context
• If you are using a view, typically you use frame
• If you are implementing a view, typically you use bounds
• Matter of perspective
■ From outside it’s usually the frame
■ From inside it’s usually the bounds
• Examples:
■ Creating a view, positioning a view in superview - use frame
■ Handling events, drawing a view - use bounds
Tuesday, January 19, 2010 21
34. Where do views come from?
• Commonly Interface Builder
• Drag out any of the existing view objects (buttons, labels, etc)
• Or drag generic UIView and set custom class
Tuesday, January 19, 2010 23
35. Manual Creation
• Views are initialized using -initWithFrame:
CGRect frame = CGRectMake(0, 0, 200, 150);
UIView *myView = [[UIView alloc] initWithFrame:frame];
• Example:
CGRect frame = CGRectMake(20, 45, 140, 21);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
[window addSubview:label];
[label setText:@”Number of sides:”];
[label release]; // label now retained by window
Tuesday, January 19, 2010 24
36. 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;
Tuesday, January 19, 2010 25
38. - (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
• When is it OK to call drawRect:?
Tuesday, January 19, 2010 27
39. Be Lazy
• drawRect: is invoked automatically
■ Don’t call it directly!
• Being lazy is good for performance
• When a view needs to be redrawn, use:
- (void)setNeedsDisplay;
• For example, in your controller:
- (void)setNumberOfSides:(int)sides {
numberOfSides = sides;
[polygonView setNeedsDisplay];
}
Tuesday, January 19, 2010 28
40. 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
Tuesday, January 19, 2010 29
41. 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!
Tuesday, January 19, 2010 30
42. CG Wrappers
• Some CG functionality wrapped by UIKit
• 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];
Tuesday, January 19, 2010 31
43. 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);
}
Tuesday, January 19, 2010 32
44. 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);
}
Tuesday, January 19, 2010 32
45. 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
Tuesday, January 19, 2010 33
46. Paths
• 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
Tuesday, January 19, 2010 34
47. CGPath
• Two parallel sets of functions for using paths
■ CGContext “convenience” throwaway functions
■ CGPath functions for creating reusable paths
CGContext CGPath
CGContextMoveToPoint CGPathMoveToPoint
CGContextAddLineToPoint CGPathAddLineToPoint
CGContextAddArcToPoint CGPathAddArcToPoint
CGContextClosePath CGPathCloseSubPath
And so on and so on . . .
Tuesday, January 19, 2010 35
50. More Drawing Information
• UIView Class Reference
• CGContext Reference
• “Quartz 2D Programming Guide”
• Lots of samples in the iPhone Dev Center
Tuesday, January 19, 2010 37
52. UIImage
• UIKit class representing an image
• Creating UIImages:
■ Fetching image in application bundle
■ Use +[UIImage imageNamed:(NSString *)name]
■ Include file extension in file name, e.g. @”myImage.jpg”
■ Read from file on disk
■ Use -[UIImage initWithContentsOfFile:(NSString *)path]
■ From data in memory
■ Use -[UIImage initWithData:(NSData *)data]
Tuesday, January 19, 2010 39
53. Creating Images from a Context
• Need to dynamically generate a bitmap image
• Same as drawing a view
• General steps
■ Create a special CGGraphicsContext with a size
■ Draw
■ Capture the context as a bitmap
■ Clean up
Tuesday, January 19, 2010 40
54. Bitmap Image Example
- (UIImage *)polygonImageOfSize:(CGSize)size {
UIImage *result = nil;
UIGraphicsBeginImageContext (size);
// call your drawing code...
result = UIGraphicsGetImageFromCurrentContext();
UIGraphicsEndImageContext();
return result;
}
Tuesday, January 19, 2010 41
55. Getting Image Data
• Given UIImage, want PNG or JPG representation
NSData *UIImagePNGRepresentation (UIImage * image);
NSData *UIImageJPGRepresentation (UIImage * image);
• UIImage also has a CGImage property which will give you a
CGImageRef to use with CG calls
Tuesday, January 19, 2010 42
56. 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]
Tuesday, January 19, 2010 43
57. 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]
But there is a better way!
Tuesday, January 19, 2010 43
59. Constructing Views
• How do I implement this?
Tuesday, January 19, 2010 45
60. Constructing Views
• How do I implement this?
• Goal
■ PolygonView that displays shape
as well as name
Tuesday, January 19, 2010 45
61. Constructing Views
• How do I implement this?
• Goal
■ PolygonView that displays shape
as well as name
• Initial thought
■ Have PolygonView draw the text
■ Inefficient when animating
Tuesday, January 19, 2010 45
62. Constructing Views
• How do I implement this?
• Goal
■ PolygonView that displays shape
as well as name
• Initial thought
■ Have PolygonView draw the text
■ Inefficient when animating
• Instead use UILabel!
■ Tastes great
■ Less filling
Tuesday, January 19, 2010 45
63. UILabel
• UIView subclass that knows how to draw text
• Properties include:
■ font
■ textColor
■ shadow (offset & color)
■ textAlignment
Tuesday, January 19, 2010 46
64. UIImageView
• UIView that draws UIImages
• Properties include:
■ image
■ animatedImages
■ animatedDuration
■ animatedRepeatCount
• contentMode property to align and scale image wrt bounds
Tuesday, January 19, 2010 47
65. UIControl
• UIView with Target-Action event handling
• Properties include:
■ enabled
■ selected
■ highlighted
• UIButton: font, title, titleColor, image, backgroundImage
• UITextField: font, text, placeholder, textColor
• See UIKit headers for plenty more
Tuesday, January 19, 2010 48
67. Animating Views
• What if you want to change layout dynamically?
• For example, a switch to disclose additional views...
Tuesday, January 19, 2010 50
68. Animating Views
• What if you want to change layout dynamically?
• For example, a switch to disclose additional views...
Tuesday, January 19, 2010 50
69. Animating Views
• What if you want to change layout dynamically?
• For example, a switch to disclose additional views...
Tuesday, January 19, 2010 50
70. 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
Tuesday, January 19, 2010 51
71. Other Animation Options
• Additional animation options
■ delay before starting
■ start at specific time
■ curve (ease in/out, ease in, ease out, linear)
■ repeat count
■ autoreverses (e.g. ping pong back and forth)
Tuesday, January 19, 2010 52
72. View Animation Example
- (void)showAdvancedOptions {
// assume polygonView and optionsView
[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];
}
Tuesday, January 19, 2010 53
73. Knowing When Animations Finish
• UIView animations allow for a delegate
[UIView setAnimationDelegate:myController];
• myController will have callbacks invoked before and after
- (void)animationWillStart:(NSString *)animationID
context:(void *)context;
- (void)animationDidStop:(NSString *)animationID
finished:(NSNumber *)finished
context:(void *)context;
• Can provide custom selectors if desired, for example
[UIView setAnimationWillStartSelector:
@selector(animationWillStart)];
[UIView setAnimationDidStopSelector:
@selector(animationDidStop)];
Tuesday, January 19, 2010 54
74. How Does It Work?
• Is drawRect: invoked repeatedly?
• Do I have to run some kind of timer in order to drive the
animation?
• Is it magic?
Tuesday, January 19, 2010 55
75. Core Animation
• Hardware accelerated rendering engine
• UIViews are backed by “layers”
• -drawRect: results are cached
■ Cached results used to render view
■ -drawRect: called only when contents change
■ Layers drawn from a separate render tree managed by separate
process
• Property animations done automatically by manipulating layers
Tuesday, January 19, 2010 56
76. View Transforms
• Every view has a transform property
■ used to apply scaling, rotation and translation to a view
• Default “Identity transform”
• CGAffineTransform structure used to represent transform
• Use CG functions to create, modify transforms
CGAffineTransform Functions (just a small example set)
CGAffineTransformScale (transform, xScale, yScale)
CGAffineTransformRotate (transform, angle)
CGAffineTransformTranslate (transform, xDelta, yDelta)
Tuesday, January 19, 2010 57
77. More Animation Information
• iPhone OS Programming Guide
■ “Modifying Views at Runtime” section
• Core Animation Programming Guide
Tuesday, January 19, 2010 58
79. Saving State Across App Launches
• NSUserDefaults to read and write prefs & state
• Singleton object:
+ (NSUserDefaults *)standardUserDefaults;
• Methods for storing & fetching common types:
- (int)integerForKey:(NSString *)key;
- (void)setInteger:(int)value forKey:(NSString *)key;
- (id)objectForKey:(NSString *)key;
- (void)setObject:(id)value forKey:(NSString *)key;
• Find an appropriate time to store and restore your state
Tuesday, January 19, 2010 60