Drawing and Printing && View Programming

Drawing and Printing Guide for iOS 

一、Custom UI Views Allow Greater Drawing Flexibility

Custom views are generally more processor-intensive (with less help from the GPU)

二、A Few Key Concepts Underpin Drawing With the Native Technologies

1. drawRect: == graphics context

2. iOS Drawing Concepts

The UIKit Graphics System

The View Drawing Cycle

redrawn == drawRect: -- trigger a view update:

<1> obscuring your view  <2> hidden property to NO  <3> Scrolling off and back

<4> setNeedsDisplay or setNeedsDisplayInRect:

drawRect: -- first time: iOS passes a rectangle to the view’s drawRect: method that contains your view’s entire visible area. subsequent calls: only the portion of the view that actually needs to be redrawn.

Coordinate Systems and Drawing in iOS

<1> The drawing (user) coordinate system. 

<2> The view coordinate system (base space). 

<3> The (physical) device coordinate system. 

(ULO) + (LLO)

Points Versus Pixels

logical coordinate spaces + device coordinate space

Obtaining Graphics Contexts


Drawing with Quartz and UIKit

Configuring the Graphics Context

Creating and Drawing Paths

UIRectFrame + UIRectFill

UIBezierPath + CGPathRef

Flipping the Default Coordinate System

Applying Core Animation Effects


三、UIKit, Core Graphics, and Core Animation Give Your App Many Tools For Drawing

1. iOS Drawing Concepts

2. Drawing Shapes Using Bézier Paths

Bézier Path Basics

<1> Create the path

<2> drawing attributes -- lineWidth + lineJoinStyle + usesEvenOddFillRule

<3> moveToPoint: - starting point

<4> Add line and curve

<5> Optionally,closePath

<6> Optionally,additional subpaths

Adding Lines and Polygons to Your Path

moveToPoint: + addLineToPoint:

Adding Arcs to Your Path

bezierPathWithArcCenter: radius: startAngle: endAngle: clockwise:

Adding Curves to Your Path

addCurveToPoint: controlPoint1: controlPoint2:

addQuadCurveToPoint: controlPoint:

Modifying the Path Using Core Graphics Functions

CGPath

Rendering the Contents of a Bézier Path Object

// If you have content to draw after the shape, save the current state before changing the transform.

// CGContextSaveGState(aRef);

Doing Hit-Detection on a Path

containsPoint:

CGContextPathContainsPoint

3. Drawing and Creating Images

<1> Drawing Images  

--  [self.anImage drawAtPoint:CGPointMake(10, 10)];

<2> Creating New Images Using Bitmap Graphics Contexts

draw something to an offscreen buffer

i. UIGraphicsBeginImageContextWithOptions -- size + opaque(transparency (an alpha channel), passNO.) + scale

ii. draw

iii. UIGraphicsGetImageFromCurrentImageContext

iv. UIGraphicsEndImageContext

4. Generating PDF Content

四、Apps Can Draw Into Offscreen Bitmaps or PDFs

1. Drawing and Creating Images

2. Generating PDF Content

五、Apps Have a Range of Options for Printing Content

1. Printing

六、It’s Easy to Update Your App for High-Resolution Screens

1. Supporting High-Resolution Screens In Views




View Programming Guide for iOS

一、Views Manage Your Application’s Visual Content

1. View and Window Architecture

创建视图-segmentItems + 做动画-isAnimating + isUpdated  --  都是性能思维

Content Modes

This means that stretchable views are supported only with the UIViewContentModeScaleToFillUIViewContentModeScaleAspectFit, and UIViewContentModeScaleAspectFill content modes.

Coordinate System Transformations

When applying transforms to a view, you must use the view’s bounds and center properties to get the size and position of the view.

The Runtime Interaction Model for Views

<1> touches  <2> hardware -> UIKit  <3> UIKit -> UIEvent dispatches

2. Views

<1> Tagging Views for Future Identification

Tag-based searches are faster than iterating the view hierarchy yourself

viewWithTag: - depth-first search

<2> A hidden view does not receive touch events from the system

you should force your view to resign the first responder status when you hide it

<3> Locating Views in a View Hierarchy

if you wanted to save the list of views that are currently visible in your application, you would write out the tags of each visible view to a file

<4> Handling Layout Changes Automatically Using Autoresizing Rules

二、Windows Coordinate the Display of Your Views

1. Windows

三、Animations Provide the User with Visible Feedback for Interface Changes

1. Animations

the specified animations are started immediately on another thread so as to avoid blocking the current thread or your application’s main thread.

<1>The UIViewAnimationOptionOverrideInheritedCurve and UIViewAnimationOptionOverrideInheritedDuration keys used in the nested animation block allow the curve and duration values from the first animation to be modified for the second animation.

<2> consider specifying a non integer value for the repeat count  --  avoid snap quickly to the new value.

<3> transitionWithView: duration: options: animations: completion:  --  Limiting animations to this set allows the view to create a snapshot image of the before and after versions of the view and animate between the two images, which is more efficient.

<4> transitionFromView: toView: duration: options: completion:  --  UIViewAnimationOptionShowHideTransitionViews - hide not remove

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,560评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,104评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,297评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,869评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,275评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,563评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,833评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,543评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,245评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,512评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,011评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,359评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,006评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,062评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,825评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,590评论 2 273
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,501评论 2 268

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 8,572评论 0 23
  • ViewsBecause view objects are the main way your applicati...
    梁光飞阅读 540评论 0 0
  • 谁没有一 段青春的印记,无论七彩缤纷,还是黯淡无光,都会在心底留下抹不去的回忆。青春的气息,一生的陶醉,留一曲...
    200c71706bbc阅读 378评论 2 5
  • 我一个朋友的孩子。早年自闭,而今可以写出比平常他骂我“怂逼”还让我兴奋的话来。 比如在看了我那篇挨千刀的《除了房价...
    拼拼黑凤梨阅读 254评论 0 1
  • 手机要藏好,心也要藏好,兜兜转转还是回到原点
    三文鱼势力阅读 79评论 0 0