Skip to Content
COCOA學習手冊--使用OBJECTIVE-C第三版
book

COCOA學習手冊--使用OBJECTIVE-C第三版

by Paris Buttfield-Addison, Jonathon Manning
June 2013
Intermediate to advanced
360 pages
6h 50m
Chinese
GoTop Information, Inc.
Content preview from COCOA學習手冊--使用OBJECTIVE-C第三版
114
|
第七章
所有繪圖作業的發生都是按照你呼叫它們的順序而進行的。在這段程式碼
中,我們在填滿矩形之後為它描邊,如果我們交換
[path fill]
[path
stroke]
呼叫的順序,就會得到稍微有點不同的效果,綠色填充會稍微覆
蓋到黑色描邊。
建立自訂軌跡
使用矩形或圓角矩形建立軌跡是很有用的,但是你常常會想要建立完全屬於你自己的形
狀—或許是多邊形,或者是人物輪廓。
NSBezierPath
類別可表示任何能以 Bezier 曲線定義的形狀。你可以建立空白曲線
blank curve),然後增加定義此曲線的控制點(control point),一旦完成,就可以利
用完成的
NSBezierPath
物件來進行描邊與填充。
為了建立自訂軌跡(custom path),首先產生空軌跡(empty path),然後開始發佈建構
它的命令。隨著軌跡被建造,你可以想像有一支虛擬畫筆在畫布上四處移動,你可以︰
把筆移到某一點
將筆從目前所在位置畫一條線到另一個點
將筆從目前所在位置畫一條曲線到另一個點,使用額外兩個控制點定義該曲線要如
何彎曲
將筆從目前所在位置畫一條線到第一個點,將軌跡封閉起來
我們現在要更新繪圖程式碼,以下列程式碼替換
drawRect
方法,繪製一個心形。因為這
個形狀取決於所指定之各個控制點的位置,這裡有不少數字要輸入。假如你無法把它們
弄得完美無誤,也不必太過擔心—這個形狀大體上應該會保持正確。
- (void)drawRect:(NSRect)dirtyRect
{
NSBezierPath* ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

網頁互動式資料視覺化:使用D3

網頁互動式資料視覺化:使用D3

Scott Murray
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
自然语言处理实战:从入门到项目实践

自然语言处理实战:从入门到项目实践

Sowmya Vajjala, Bodhisattwa Majumder, Anuj Gupta, Harshit Surana

Publisher Resources

ISBN: 9789862768136