頁面切換動畫:@"添加" , @"翻頁" , @"移入" , @"揭開" , @"立方體" , @"收縮" , @"翻轉(zhuǎn)" , @"水波"

#import#import "FKViewController.h"

@implementation FKViewController

- (void)viewDidLoad

{

[super viewDidLoad];

UIView *magentaView = [[UIView alloc] initWithFrame:self.view.bounds];

magentaView.backgroundColor = [UIColor magentaColor];

[self.view addSubview:magentaView];

UIView* grayView = [[UIView alloc] initWithFrame:self.view.bounds];

grayView.backgroundColor = [UIColor lightGrayColor];

[self.view addSubview:grayView];

NSArray* bnTitleArray = [NSArray arrayWithObjects:

@"添加" , @"翻頁" , @"移入" , @"揭開" ,

@"立方體" , @"收縮" , @"翻轉(zhuǎn)" , @"水波" , nil];

NSMutableArray* bnArray = [[NSMutableArray alloc] init];

// 獲取屏幕的內(nèi)部高度

CGFloat totalHeight = [UIScreen mainScreen].bounds.size.height;

// 創(chuàng)建8個按鈕店量,并將按鈕添加到NSMutableArray集合中

for (int i = 0 ; i < 8 ; i++)

{

UIButton* bn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[bn setTitle:[bnTitleArray objectAtIndex:i]

forState:UIControlStateNormal];

NSInteger row = i / 4;

NSInteger col = i % 4;

bn.frame = CGRectMake(5 + col * 80

, totalHeight - (2 - row) * 45 - 20 , 70 , 35);

[self.view addSubview:bn];

[bnArray addObject:bn];

}

// 為8個按鈕分別綁定不同的事件處理方法

[[bnArray objectAtIndex:0] addTarget:self action:@selector(add:)

forControlEvents:UIControlEventTouchUpInside];

[[bnArray objectAtIndex:1] addTarget:self action:@selector(curl:)

forControlEvents:UIControlEventTouchUpInside];

[[bnArray objectAtIndex:2] addTarget:self action:@selector(move:)

forControlEvents:UIControlEventTouchUpInside];

[[bnArray objectAtIndex:3] addTarget:self action:@selector(reveal:)

forControlEvents:UIControlEventTouchUpInside];

[[bnArray objectAtIndex:4] addTarget:self action:@selector(cube:)

forControlEvents:UIControlEventTouchUpInside];

[[bnArray objectAtIndex:5] addTarget:self action:@selector(suck:)

forControlEvents:UIControlEventTouchUpInside];

[[bnArray objectAtIndex:6] addTarget:self action:@selector(oglFlip:)

forControlEvents:UIControlEventTouchUpInside];

[[bnArray objectAtIndex:7] addTarget:self action:@selector(ripple:)

forControlEvents:UIControlEventTouchUpInside];

NSLog(@"~~~~~~~%@" , [[self.view.subviews objectAtIndex:2] backgroundColor]);

NSLog(@"~~~~~~~%@" , [[self.view.subviews objectAtIndex:3] backgroundColor]);

}

-(void) add:(id)sender

{

// 開始執(zhí)行動畫

[UIView beginAnimations:@"animation" context:nil];

[UIView setAnimationDuration:1.0f];

// 控制UIView內(nèi)過渡動畫的類型

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown

forView:self.view cache:YES];

// 設(shè)置動畫的變化曲線

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

// 提交動畫

[UIView commitAnimations];

}

-(void) curl:(id)sender

{

// 開始執(zhí)行動畫

[UIView beginAnimations:@"animation" context:nil];

[UIView setAnimationDuration:1.0f];

// 控制UIView內(nèi)過渡動畫的類型

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp

forView:self.view cache:YES];

// 設(shè)置動畫的變化曲線

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

// 交換視圖控制器所顯示的UIView中中2個子控件位置

[self.view exchangeSubviewAtIndex:3 withSubviewAtIndex:2];

[UIView commitAnimations];

}

-(void) move:(id)sender

{

CATransition *transition = [CATransition animation];

transition.duration = 2.0f;

// 使用kCATransitionMoveIn動畫

transition.type = kCATransitionMoveIn;

// 指定動畫方向证九,從左向右

transition.subtype = kCATransitionFromLeft;

[self.view.layer addAnimation:transition forKey:@"animation"];

[self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}

-(void) reveal:(id)sender

{

CATransition *transition = [CATransition animation];

transition.duration = 2.0f;

// 使用kCATransitionReveal動畫

transition.type = kCATransitionReveal;

// 指定動畫方向,從上到下

transition.subtype = kCATransitionFromTop;

[self.view.layer addAnimation:transition forKey:@"animation"];

// 交換視圖控制器所顯示的UIView中中2個子控件位置

[self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}

-(void) cube:(id)sender

{

CATransition *transition = [CATransition animation];

transition.duration = 2.0f;

// 使用@"cube"動畫

transition.type = @"cube";

// 指定動畫方向允跑,從左到右

transition.subtype = kCATransitionFromLeft;

[self.view.layer addAnimation:transition forKey:@"animation"];

// 交換視圖控制器所顯示的UIView中中2個子控件位置

[self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}

-(void) suck:(id)sender

{

CATransition *transition = [CATransition animation];

transition.duration = 2.0f;

// 使用@"suck"動畫, 該動畫與動畫方向無關(guān)

transition.type = @"suckEffect";

[self.view.layer addAnimation:transition forKey:@"animation"];

// 交換視圖控制器所顯示的UIView中中2個子控件位置

[self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}

-(void) oglFlip:(id)sender

{

CATransition *transition = [CATransition animation];

transition.duration = 2.0f;

// 使用@"oglFlip"動畫

transition.type = @"oglFlip";

// 指定動畫方向?yàn)樯舷路D(zhuǎn)

transition.subtype = kCATransitionFromBottom;

[self.view.layer addAnimation:transition forKey:@"animation"];

// 交換視圖控制器所顯示的UIView中中2個子控件位置

[self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}

-(void) ripple:(id)sender

{

CATransition *transition = [CATransition animation];

transition.duration = 2.0f;

// 使用@"rippleEffect"動畫脆烟,該動畫與方向無關(guān)

transition.type = @"rippleEffect";

[self.view.layer addAnimation:transition forKey:@"animation"];

// 交換視圖控制器所顯示的UIView中中2個子控件位置

[self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

}

@end

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末颇象,一起剝皮案震驚了整個濱河市靠娱,隨后出現(xiàn)的幾起案子屯烦,更是在濱河造成了極大的恐慌,老刑警劉巖首启,帶你破解...
    沈念sama閱讀 216,651評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異撤摸,居然都是意外死亡毅桃,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,468評論 3 392
  • 文/潘曉璐 我一進(jìn)店門准夷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來钥飞,“玉大人,你說我怎么就攤上這事衫嵌《林妫” “怎么了?”我有些...
    開封第一講書人閱讀 162,931評論 0 353
  • 文/不壞的土叔 我叫張陵楔绞,是天一觀的道長结闸。 經(jīng)常有香客問我,道長酒朵,這世上最難降的妖魔是什么桦锄? 我笑而不...
    開封第一講書人閱讀 58,218評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮蔫耽,結(jié)果婚禮上结耀,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好图甜,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,234評論 6 388
  • 文/花漫 我一把揭開白布碍粥。 她就那樣靜靜地躺著,像睡著了一般黑毅。 火紅的嫁衣襯著肌膚如雪嚼摩。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,198評論 1 299
  • 那天博肋,我揣著相機(jī)與錄音低斋,去河邊找鬼。 笑死匪凡,一個胖子當(dāng)著我的面吹牛膊畴,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播病游,決...
    沈念sama閱讀 40,084評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼唇跨,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了衬衬?” 一聲冷哼從身側(cè)響起买猖,我...
    開封第一講書人閱讀 38,926評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎滋尉,沒想到半個月后玉控,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,341評論 1 311
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡狮惜,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,563評論 2 333
  • 正文 我和宋清朗相戀三年高诺,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片碾篡。...
    茶點(diǎn)故事閱讀 39,731評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡虱而,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出开泽,到底是詐尸還是另有隱情牡拇,我是刑警寧澤,帶...
    沈念sama閱讀 35,430評論 5 343
  • 正文 年R本政府宣布穆律,位于F島的核電站惠呼,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏峦耘。R本人自食惡果不足惜罢杉,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,036評論 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望贡歧。 院中可真熱鬧滩租,春花似錦赋秀、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,676評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至技即,卻和暖如春著洼,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背而叼。 一陣腳步聲響...
    開封第一講書人閱讀 32,829評論 1 269
  • 我被黑心中介騙來泰國打工身笤, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人葵陵。 一個月前我還...
    沈念sama閱讀 47,743評論 2 368
  • 正文 我出身青樓液荸,卻偏偏與公主長得像,于是被迫代替她去往敵國和親脱篙。 傳聞我的和親對象是個殘疾皇子娇钱,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,629評論 2 354

推薦閱讀更多精彩內(nèi)容