2010/12/16 朱中華.  這個程式會先在 iPhone 螢幕上顯示 This is the Front View 及箭頭, click 任何地方後, 畫面會翻轉 (transition) 至下個畫面 ---This is the Back View 及箭頭,每次 click ,交替出 現,見下圖。

Slides:



Advertisements
Similar presentations
FCU, Department of ECE, IC Design Research Lab. TEL: # 4945 Pre-SIm , Post-Sim.
Advertisements

Chapter 10 馬可夫鏈 緒言 如果讀者仔細觀察日常生活中所發生的 諸多事件,必然會發現有些事件的未來 發展或演變與該事件現階段的狀況全然 無關,這種事件稱為獨立試行過程 (process of independent trials) ;而另一些 事件則會受到該事件現階段的狀況影響。
: Arrange the Numbers ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11481: Arrange the Numbers 解題者:李重儀 解題日期: 2008 年 9 月 13 日 題意: 將數列 {1,2,3, …,N}
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
Introduction to Java Programming Lecture 13 Classes I OO Programming.
: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
:Word Morphing ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10508:word morphing 解題者:楊家豪 解題日期: 2006 年 5 月 21 日 題意: 第一行給你兩個正整數, 第一個代表下面會出現幾個字串,
3Com Switch 4500 切VLAN教學.
What is static?. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1; this.instanceX =
指導教授:陳淑媛 學生:李宗叡 李卿輔.  利用下列三種方法 (Edge Detection 、 Local Binary Pattern 、 Structured Local Edge Pattern) 來判斷是否為場景變換,以方便使用者來 找出所要的片段。
1 Web of Science 利用指引 單元二 瀏覽與處理查詢結果. 2 瀏覽檢索結果 查出的結果,預設以時間排列, 使用者可改變結果的排列方式: 還可以依被引用次數、相關度、 第一作者、刊名、出版年等排序 回到前先查的結果畫面 點選想看資料的完整書目 本館訂購範圍的期刊 全文,便可直接連結.
五小專案 黃詩晴 章乃云. 目錄 計算機 智慧盤 拼圖 記憶大挑戰 數學題庫 心得 參考文獻.
亂數產生器安全性評估 之統計測試 SEC HW7 姓名:翁玉芬 學號:
: OPENING DOORS ? 題組: Problem Set Archive with Online Judge 題號: 10606: OPENING DOORS 解題者:侯沛彣 解題日期: 2006 年 6 月 11 日 題意: - 某間學校有 N 個學生,每個學生都有自己的衣物櫃.
: ShellSort ★★☆☆☆ 題組: Problem D 題號: 10152: ShellSort 解題者:林一帆 解題日期: 2006 年 4 月 10 日 題意:烏龜王國的烏龜總是一隻一隻疊在一起。唯一改變烏龜位置 的方法為:一隻烏龜爬出他原來的位置,然後往上爬到最上方。給 你一堆烏龜原來排列的順序,以及我們想要的烏龜的排列順序,你.
MATLAB 程式設計 第 11 章 多維陣列 多維陣列的定義 在 MATLAB 的資料型態中,向量可視為 一維陣列,矩陣可視二維陣列,對於維 度 (Dimensions) 超過 1 的陣列則均可視 為「多維陣列」 (Multidimesional Arrays , 簡稱 N-D Arrays)
1 網路同步學習 如何使用中山大學管理學院知識管理平台 愷中 製作. 2 如何登入中山大學網路學習平台 1. 首先, 請輸入 2. 點選申請帳號, 依照螢幕所示, 輸入個人資訊.
國立中山大學財產管理系統 線上報廢、盤點系統 總務處保管組 策劃 計算機與網路中心 分析設計 2008/03.
長訊科技 EVRCOM Voice Mail System 使用者操作說明及流程. 自動總機 -- 來電語音轉接服務流程 ( 範例流程 )
具備人臉追蹤與辨識功能的一個 智慧型數位監視系統 系統架構 在巡邏模式中 ,攝影機會左右來回巡視,並 利用動態膚色偵測得知是否有移動膚色物體, 若有移動的膚色物體則進入到追蹤模式,反之 則繼續巡視。
Chapter 13 塑模靜態觀點:物件圖 Static View : Object Diagram.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
:Problem D: Bit-wise Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10232: Problem D: Bit-wise Sequence 解題者:李濟宇 解題日期: 2006 年 4 月 16.
24-6 設定開始與結束場景中的 程式 最後我們要替這個遊戲收個尾, 幫它把開始 的等待畫面跟結束畫面處理一下。
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
3-3 使用幾何繪圖工具 Flash 的幾何繪圖工具包括線段工具 (Line Tool) 、橢圓形工具 (Oval Tool) 、多邊星形 工具 (Rectangle Tool) 3 種。這些工具畫出 來的幾何圖形包括了筆畫線條和填色區域, 將它們適當地組合加上有技巧地變形與配 色, 不但比鉛筆工具簡單,
Matlab Assignment Due Assignment 兩個 matlab 程式 : Eigenface : Eigenvector 和 eigenvalue 的應用. Fractal : Affine transform( rotation, translation,
Chapter 20 塑模動態觀點:狀態圖 Statechart Diagram. 學習目標  說明狀態圖的目的  定義狀態圖的基本記號  展示狀態圖的建構  定義活動、內部事件及遞延事件的狀態 圖記號.
圖層的操作與管理 圖層的作用就如同一張張透明的賽璐璐片, 你可以將動畫中的每項物件, 放置在不同圖 層中, 圖層交疊就形成完整的畫面。在各圖 層中的物件, 做任何的移動或變化, 都不會 相互干擾, 所以當你編輯一個物件時, 只要 在物件所在的圖層進行操作, 將可大幅降低 製作過程的複雜度與難度。
: Happy Number ★ ? 題組: Problem Set Archive with Online Judge 題號: 10591: Happy Number 解題者:陳瀅文 解題日期: 2006 年 6 月 6 日 題意:判斷一個正整數 N 是否為 Happy Number.
影像處理學習營 練習(三)製作影片 【上】 影像處理學習營 教師 吳清月. 製作影片 學習重點 一. 利用 movie maker 軟體,編輯相片。  加上文字幕,與圖片結合。
: Fast and Easy Data Compressor ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10043: Fast and Easy Data Compressor 解題者:葉貫中 解題日期: 2007 年 3.
: Problem A : MiniMice ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11411: Problem A : MiniMice 解題者:李重儀 解題日期: 2008 年 9 月 3 日 題意:簡單的說,題目中每一隻老鼠有一個編號.
第十章 再論結構. 指標與結構的關係 /* File name: ex10-1a.c */ #include int main() { struct student { char *name; int score; }; struct student st= {"Brian", 97}; struct.
: Ahoy, Pirates! ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11402: Ahoy, Pirates! 解題者:李重儀 解題日期: 2008 年 8 月 26 日 題意:有一個海盜島有 N 個海盜,他們的編號 (id)
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
1-6 動畫的文件屬性 舞台是動畫實際播放的畫面, 所以舞台的大 小與長寬比例對將來動畫的呈現有很大的 影響。 Flash 預設的舞台尺寸是 550 Pixels × 400 Pixels, 背景為白色, 如果要更改舞台大小與 背景色, 請執行『修改 / 文件』命令, 開啟文 件屬性 (Document.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
資料結構實習-一 參數傳遞.
6-2 認識元件庫與內建元件庫 Flash 的元件庫分兩種, 一種是每個動畫專 屬的元件庫 (Library) ;另一種則是內建元 件庫 (Common Libraries), 兩者皆可透過 『視窗』功能表來開啟, 以下即為您說明。
Dynamic Multi-signatures for Secure Autonomous Agents Panayiotis Kotzanikolaou Mike Burmester.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
公用品.  該物品的數量不會因一人的消費而受到 影響,它可以同時地被多人享用。 角色分配  兩位同學當我的助手,負責:  其餘各人是投資者,每人擁有 $100 , 可以投資在兩種資產上。  記錄  計算  協助同學討論.
: Problem G e-Coins ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10306: Problem G e-Coins 解題者:陳瀅文 解題日期: 2006 年 5 月 2 日 題意:給定一個正整數 S (0
: A-Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10930: A-Sequence 解題者:陳盈村 解題日期: 2008 年 5 月 30 日 題意: A-Sequence 需符合以下的條件, 1 ≤ a.
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
第 9 章 TSR 程式基本教練. 本章提要 TSR 程式 以熱鍵 (Hot key) 叫用 TSR 程式 Clock 中斷 int 08h 、 int 1ch DOS reentrant 的問題 有用的 TSR 程式.
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
資料結構實習-二.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
-Antidifferentiation- Chapter 6 朝陽科技大學 資訊管理系 李麗華 教授.
逆向選擇和市場失調. 定義  資料不對稱 在交易其中,其中一方較對方有多些資料。  逆向選擇 出現在這個情況下,就是當買賣雙方隨意在 市場上交易,與比較主動交易者作交易為佳 。
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Linguistics phonetic symbols. 先下載 IPA 字型檔案,執行安裝。 由於這個程式的字型目錄設定錯誤, 所以等重新開機時就會發現字型消失。 所以必須根據以下步驟來讓 Windows 加入 IPA 字型。
Chapter 10 m-way 搜尋樹與B-Tree
: Function Overloading ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11032:Function Overloading 解題者:許智祺 解題日期: 2007 年 5 月 8 日 題意:判對輸入之數字是否為.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
2005/7 Linear system-1 The Linear Equation System and Eliminations.
中序轉後序 藉由由左向右掃瞄中序運算式產生後序運算式,遇到 運算元就直接輸出,遇到運算符號則先存入堆疊,將 優先權較高者輸出。 範例: a + b * c TokenStack [0] [1] [2] topoutput aa ++0a b+0ab *+ *1ab c+ *1abc eosabc*+
: Problem E Antimatter Ray Clearcutting ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11008: Problem E Antimatter Ray Clearcutting 解題者:林王智瑞.
Teacher : Ing-Jer Huang TA : Chien-Hung Chen 2015/6/30 Course Embedded Systems : Principles and Implementations Weekly Preview Question CH7.1~CH /12/26.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2008.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2010.
: SAM I AM ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11419: SAM I AM 解題者:李重儀 解題日期: 2008 年 9 月 11 日 題意: 簡單的說,就是一個長方形的廟裡面有敵人,然 後可以橫的方向開砲或縱向開砲,每次開砲可以.
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Problem E.Stone Game ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10165: Problem E.Stone Game 解題者:李濟宇 解題日期: 2006 年 3 月 26 日 題意: Jack 與 Jim.
著作權所有 © 旗標出版股份有限公司 第 14 章 製作信封、標籤. 本章提要 製作單一信封 製作單一郵寄標籤.
幼兒行為觀察與記錄 第八章 事件取樣法.
: How many 0's? ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11038: How many 0’s? 解題者:楊鵬宇 解題日期: 2007 年 5 月 15 日 題意:寫下題目給的 m 與 n(m
1 柱體與錐體 1. 找出柱體與錐體的規則 2. 柱體的命名與特性 3. 柱體的展開圖 4. 錐體的命名與特性 5. 錐體的展開圖
Presentation transcript:

2010/12/16 朱中華

 這個程式會先在 iPhone 螢幕上顯示 This is the Front View 及箭頭, click 任何地方後, 畫面會翻轉 (transition) 至下個畫面 ---This is the Back View 及箭頭,每次 click ,交替出 現,見下圖。

 新產生 FlipView class 的 touchesEnded : 產生 flip 效果的方式由 14 、 19 行達成,  14 行, [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES];  15 行, [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1 ];

 #import // Note: although Apple promised UIViewAnimationTransitionCurlUp as a transition, it's not live FlipView FlipView - (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { // Start Animation Block CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1.0]; // Animations [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; // Commit Animation Block [UIView commitAnimations];

 以下是 loadView 程式:  由 38~44 行先將 This is the Front View 、 This is the Back View load 進來。  47~54 行加上 "This is the Front View" ,是 以 label 方式。  其後是以 label 方式加上 "This is the Back View" 。  66~67 行先 addSubview:backView 再 addSubview:frantView ,後加的在上面, 因此 frontView 在 front 。

HelloController HelloController - (void)loadView { // Create the main view UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; contentView.backgroundColor = [UIColor blackColor]; self.view = contentView; [contentView release]; FlipView *frontView = [[FlipView alloc] initWithFrame:self.view.bounds]; frontView.image = [UIImage frontView.userInteractionEnabled = YES; FlipView *backView = [[FlipView alloc] initWithFrame:self.view.bounds]; backView.image = [UIImage backView.userInteractionEnabled = YES; // Add an identifying label for front CGRect labelFrame = CGRectMake(40.0f, 200.0f, 240.0f, 60.0f); UILabel *frontLabel = [[UILabel alloc] initWithFrame:labelFrame]; frontLabel.text is the Front View"; frontLabel.font = [UIFont size:24.0f]; frontLabel.textColor = [UIColor colorWithRed:0.82f green:1.0f blue:0.286f alpha:1.0f]; frontLabel.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f]; [frontView addSubview:frontLabel]; [frontLabel release]; // Add an identifying label for back UILabel *backLabel = [[UILabel alloc] initWithFrame:labelFrame]; backLabel.text is the Back View"; backLabel.font = [UIFont size:24.0f]; backLabel.textColor = [UIColor colorWithRed:0.82f green:1.0f blue:0.286f alpha:1.0f]; backLabel.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f]; [backView addSubview:backLabel]; [backLabel release]; // add the views [self.view addSubview:backView]; [self.view addSubview:frontView]; [backView release]; [frontView release];

SampleAppDelegate SampleAppDelegate - (void)applicationDidFinishLaunching:(UIApplication *)application { UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; HelloController *hello = [[HelloController alloc] init]; [window addSubview:hello.view]; [window makeKeyAndVisible]; int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, [pool release]; return retVal; }

 這個程式讓使用者 click 後往上下左右 swipe , 圖就會依方向更換。如下圖。往右或往上。

 FlipView class 是主軸,其中 instance variable , startTouchPosition 及 dirString 表示 click 開始點及 swipe 方向。 init 會 setMultipleTouchEnabled 。 getAnimation: direction 會得到 animation 的方向。 注意:改一下 type ,會成為 flip  #import #import FlipView : UIImageView { CGPoint startTouchPosition; NSString *dirString;

FlipView - (FlipView *) init { self = [super init]; [self setMultipleTouchEnabled:YES]; return self; } - (CATransition *) getAnimation:(NSString *) direction { CATransition *animation = [CATransition animation]; [animation setDelegate:self]; // [animation [animation setType:kCATransitionPush]; [animation setSubtype:direction]; [animation setDuration:1.0f]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; return animation; }

 touchesBegan 時,將 startTouchPosition 記下。  touchesMoved 時,由 ( startTouchesPosition.x - currentTouchPosition.x ) 及 ( startTouchesPosition.y - currentTouchPosition.y ) 判斷是否橫向移動。由 ( startTouchesPosition.y - currentTouchPosition.y ) 及 ( startTouchesPosition.x - currentTouchPosition.x ) 判斷是否縱向移動。  touchesEnded 時,若有 dirString 時,作移動的 animation 動作。

 #define HORIZ_SWIPE_DRAG_MIN 12 #define VERT_SWIPE_DRAG_MAX 4 // The following swipe code derives from Apple Sample Code - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; startTouchPosition = [touch locationInView:self]; dirString = NULL; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = touches.anyObject; CGPoint currentTouchPosition = [touch locationInView:self]; if (fabsf(startTouchPosition.x - currentTouchPosition.x) >= HORIZ_SWIPE_DRAG_MIN && fabsf(startTouchPosition.y - currentTouchPosition.y) = HORIZ_SWIPE_DRAG_MIN && fabsf(startTouchPosition.x - currentTouchPosition.x) <= VERT_SWIPE_DRAG_MAX) { // Vertical Swipe if (startTouchPosition.y < currentTouchPosition.y) dirString = kCATransitionFromBottom; else dirString = kCATransitionFromTop; } else { // Process a non-swipe event. // dirString = NULL; } }

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (dirString) { CATransition *animation = [self getAnimation:dirString]; [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; [[[self superview] layer] addAnimation:animation forKey:kAnimationKey]; }

 先用 loadView load 進兩張圖片:先 load backside.png ,再 load frontside.png HelloController HelloController - (void)loadView { // Create the main view UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; contentView.backgroundColor = [UIColor blackColor]; self.view = contentView; [contentView release]; UIImageView *backView = [[FlipView alloc] initWithFrame:self.view.bounds]; [backView setImage:[UIImage [backView setUserInteractionEnabled:YES]; [self.view addSubview:backView]; [backView release]; UIImageView *frontView = [[FlipView alloc] initWithFrame:self.view.bounds]; [frontView setImage:[UIImage [frontView setUserInteractionEnabled:YES]; [self.view addSubview:frontView]; [frontView release];

SampleAppDelegate SampleAppDelegate // On launch, create a basic window - (void)applicationDidFinishLaunching:(UIApplication *)application { UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; HelloController *hello = [[HelloController alloc] init]; [window addSubview:hello.view]; [window makeKeyAndVisible];

 int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, [pool release]; return retVal; }

 這個程式會先在 iPhone 螢幕上顯示數字 1 , click 後 1 會以動畫方式逐漸消失、 2 會以動 畫方式逐漸出現,每次 click ,交替出現 1 、 2 ,見下圖。

 toggleView class 的 initWithFrame 。  先看 IMAGE_VIEW_1 及 IMAGEVIEW_2 兩個 constant ,若有多個 view ,替每個 view 編號十分重 要,如此即可叫出某特定 view 。  BIGRECT 及 SMALLRECT 定出 view 的 boundary 。 注意,由左上角算起, BIGRECT 由 (0,0) 展開 (320,435) 大的 rectangle , SMALLRECT 由 ( 130, 187 ) 展開 (60, 60) 大的 rectangle 。 isOne 表示 1 是 否在 2 之上, YES 表示 1 在 2 之上, NO 表示 1 在 2 之下。  將 one.jpg 及 two.jpg load 進 memory ,先 addSubview two.png 再 addSubview one.png 會讓 one.png 自動在上方。

 #define IMAGE_VIEW_1100 #defineIMAGE_VIEW_2101 #define BIGRECT CGRectMake(0.0f, 0.0f, 320.0f, 435.0f) #define SMALLRECT CGRectMake(130.0f, 187.0f, 60.0f, 60.0f) ToggleView: UIView { BOOL ToggleView - (id) initWithFrame: (CGRect) aFrame; { self = [super initWithFrame:aFrame]; // Load both views, make them non-interactive UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:BIGRECT]; imgView1.image = [UIImage imgView1.userInteractionEnabled = NO; imgView1.tag = IMAGE_VIEW_1; UIImageView *imgView2 = [[UIImageView alloc] initWithFrame:SMALLRECT]; imgView2.image = [UIImage imgView2.userInteractionEnabled = NO; imgView2.tag = IMAGE_VIEW_2; // image 1 is in front of image 2 to begin [self addSubview:imgView2]; [self addSubview:imgView1]; isOne = YES; [imgView1 release]; [imgView2 release]; return self; }

 程式中 ToggleView class 為核心,若將其中 的 touchesBegan 程式稍加修改,由 0.5 改為 0.7 ,可將隱藏在下的數字 "1" 顯現出來。這 正是 " 數字 2" 在上方 (frontView) , " 數字 1" 在 下方的明確表現。

 toggleView class 的 touchesBegan :  先把在上面的 image 放在 big ,下面的放在 small 。  動畫參數設好。注意 48 行 setAnimationDuration 後的數字改成 8.0(8 秒 ) ,這是讓過程緩慢呈現,以便 copy screen 方便。 原來是 1.0 。  swap 上、下圖的 boundary 。注意, 51 行的 setAlpha 為 0.5 ,因 big 要 到下面去了。 執行動畫。  將 big 的動畫隱藏起來。  將 big 放到 frontView 。這一行耐人尋味,明明 big 就已經在 frontView( 尤其是第一個畫面, imgView1 在 front) 了,為何還要再放 front 一次?原因十分簡單,現在的 big ,馬上要成為 little 了,如果不 放在 front ,若想看就看不見。試著 comment 掉 58 行,這時 1 、 2 都會 出現,這就是 59 行的作用。再試著 comment 掉 58 、 59 行,這時 1 是 big 時,看不見 2 ,因為 28~29 行, imgView1 永遠在 front ,小 boundary 的 2 就被蓋住了。 2 是 big 時,看得見 1 ,因為 28~29 行, imgView1 永遠在 front 。由此可知, bringSubviewFront 很好用,一 大 frame 一小 frame 時,只要將小 frame bringSubviewFront ,再加上 setAlpha:0.5( 或小於 1) ,就會出現重疊效果。

 - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { // Determine which view occupies which role UIImageView *big = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_1 : IMAGE_VIEW_2)]; UIImageView *little = (UIImageView *)[self viewWithTag: (isOne ? IMAGE_VIEW_2 : IMAGE_VIEW_1)]; isOne = !isOne; // Pack all the changes into the animation block CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1.0]; [big setFrame:SMALLRECT]; [big setAlpha:0.5]; [little setFrame:BIGRECT]; [little setAlpha:1.0]; [UIView commitAnimations]; // Hide the shrunken "big" image. [big setAlpha:0.0f]; [[big superview] bringSubviewToFront:big];

HelloController HelloController - (void)loadView { ToggleView *contentView = [[ToggleView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; contentView.backgroundColor = [UIColor whiteColor]; self.view = contentView; [contentView release];

SampleAppDelegate SampleAppDelegate - (void)applicationDidFinishLaunching:(UIApplication *)application { UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; HelloController *hello = [[HelloController alloc] init]; [window addSubview:hello.view]; [window makeKeyAndVisible]; int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, [pool release]; return retVal; }

 這程式主要是分別顯示 Lime 、 Orange 、 Pink 三種顏色在螢幕上,每 種同顏色畫面有不同的 Navigation Bar 。 Lime 畫面中間 title 是 Lime 、右有一個 Orange Button ,按下 Orange Button 則出現 Orange 畫面。 Orange 畫面中間 title 是 Orange ,左有 Lime Button ,按下 Lime Button 則回到 Lime 畫面,右有一個 Pink Button ,按下 Pink Button 則出現 Pink 畫面。 Pink 畫面中間 title 是 Pink ,左有一個 Orange Button ,按 下 Orange Button 則回到 Orange 畫面。如下圖。

 如下各個圖所示,程式包含三個 UIViewController , LimeController(7 行 ) 、 PinkController(10 行 ) 、 OrangeController(13 行 ) 。重點是 PinkController(10 行 ) 、 OrangeController(13 行 ) 均 inherit 自 LimeController ,因而:  三者有各自的 init 、 loadView 、 loadButton 、 switch ,但是只有 LimeController 有完整的 loadView(32~41 行 ) ,及其他的 Task ,例如: shouldAutorotateToInterfaceOrientation 。看一下 LimeController 完整的 loadView(32~41 行 ) :

 34 行: alloc 一個 UIView 。  35 行:設定顏色 Lime 。  36 、 37 行:設定 autoresize 特性。  38 行:指定這個 UIView 為 LimeController 的 view 。  39 行: release memory 。  40 行:呼叫 loadButton(40 行 ) ,將 Orange Button 放進 Navigation Bar(25 行 ) ,也將 action 定為 switch(29 行 ) 。 switch(43 行 ) 則會 pushViewController -- OrangeController(45 行 ) ,造成畫面轉換至 Orange 。

 在 OrangeController 中, loadView 內 call [super loadView](72 行 ) , 就會跳至 32 行去執行 LimeController 內的 loadView ,但是卻不是完全 照 LimeController 內 callLimeController 的 loadButton 、 switch ,而且 call OrangeController 自己的 loadButton 及 switch ,進入 LimeController 的 loadView(32 行 ) 後詳如下:  34 行: alloc 一個 UIView 。  35 行:設定顏色 Lime 。 ( 未來 73 行再重設為 ORANGE)  36 、 37 行:設定 autoresize 特性。  38 行:指定這個 UIView 為 OrangeController 的 view 。 ( 此時 self 是 OrangeController)  39 行: release memory 。  40 行:呼叫 loadButton(61 行、這是 OrangeController 的 loadButton) ,將 Pink Button 放進 Navigation Bar(64 行 ) ,也將 action 定為 switch(67 行 ) ,但是這個 switch 是 OrangeController 的 switch ,在 76 行。 switch(76 行 ) 則會 pushViewController -- PinkController(78 行 ) , 造成畫面轉換至 Pink 。  執行完 [super loadView] , 73 行的 self.view.backgroundColor = ORAGNE ;將畫面換成 oragne

 在 PinkController 中, loadView 內 call [super loadView](96 行 ) ,就 會跳至 32 行去執行 LimeController 內的 loadView ,但是卻不是完全照 LimeController 內 callLimeController 的 loadButton 、 switch ,而且 call PinkController 自己的 loadButton 及 switch ,進入 LimeController 的 loadView(32 行 ) 後詳如下:  34 行: alloc 一個 UIView 。  35 行:設定顏色 Lime 。 ( 未來 97 行再重設為 PINK)  36 、 37 行:設定 autoresize 特性。  38 行:指定這個 UIView 為 PinkController 的 view 。 ( 此時 self 是 PinkController)  39 行: release memory 。  40 行:呼叫 loadButton(89 行、這是 PinkController 的 loadButton) , loadButton 不做任何事,因為不需再放一個 button ,但是 PinkController 必需有自己的 loadButton ,否則會 call 到 LimeController 的 loadButton 。  執行完 [super loadView] , 97 行的 self.view.backgroundColor = PINK ;將畫面換成 pink 。

 #define PINK [UIColor colorWithRed:0.925f green:0.0f blue:0.549f alpha:1.0f] #define LIME [UIColor colorWithRed:0.82f green:1.0f blue:0.286f alpha:1.0f] #define ORANGE [UIColor colorWithRed:1.0f green:0.522f blue:0.03f OrangeController:

LimeController - (id) init { if (self = [super init]) self.title return self; } - (void) loadButton { self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] style:UIBarButtonItemStylePlain target:self } - (void)loadView { UIView *contentView = [[UIView alloc] init]; contentView.backgroundColor = LIME; contentView.autoresizesSubviews = YES; contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); self.view = contentView; [contentView release]; [self loadButton]; }

 - (void) switch: (id) sender { [[self navigationController] pushViewController:[[OrangeController alloc] init] animated:YES]; } -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return OrangeController - (id) init { if (self = [super init]) self.title return self; } - (void) loadButton { self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] style:UIBarButtonItemStylePlain target:self }

 - (void) loadView { [super loadView]; self.view.backgroundColor = ORANGE; } - (void) switch: (id) sender { [[self navigationController] pushViewController:[[PinkController alloc] init] PinkController - (id) init { if (self = [super init]) self.title return self; } - (void) loadButton { return; }

 - (void) loadView { [super loadView]; self.view.backgroundColor = SampleAppDelegate SampleAppDelegate - (void)applicationDidFinishLaunching:(UIApplication *)application { UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[LimeController alloc] init]]; [window addSubview:nav.view]; [window makeKeyAndVisible]; int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, [pool release]; return retVal; }