?- (void)viewDidLoad {
??? [super viewDidLoad];
??? // Do any additional setup after loading the view, typically from a nib.
??? UIView *magentaView = [[UIView alloc] initWithFrame:self.view.bounds];
??? magentaView.backgroundColor = [UIColor magentaColor];
?? ?
??? [self.view addSubview:magentaView];
???
??? NSLog(@"====%@",[self.view subviews]);
???
??? 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:3.0f];
??? // 控制UIView內(nèi)過渡動畫的類型
??? [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
?????????????????????????? forView:self.view cache:YES];
??? // 設(shè)置動畫的變化曲線
??? [UIView setAnimationCurve:UIViewAnimationCurveLinear];
??? // 提交動畫
??? [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:UIViewAnimationCurveLinear];
??? // 交換視圖控制器所顯示的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 = 0.5f;
??? // 使用@"oglFlip"動畫
??? transition.type = @"oglFlip";
??? // 指定動畫方向為上下翻轉(zhuǎn)
??? transition.subtype = kCATransitionFromLeft;
??? [self.view.layer addAnimation:transition forKey:@"animation"];
??? // 交換視圖控制器所顯示的UIView中中2個子控件位置
??? [self.view exchangeSubviewAtIndex:1 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];
}
- (void)didReceiveMemoryWarning {
??? [super didReceiveMemoryWarning];
??? // Dispose of any resources that can be recreated.
}
?
iOS 各種動畫效果展示
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門施蜜,熙熙樓的掌柜王于貴愁眉苦臉地迎上來卒蘸,“玉大人,你說我怎么就攤上這事翻默「孜郑” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵修械,是天一觀的道長趾牧。 經(jīng)常有香客問我,道長肯污,這世上最難降的妖魔是什么翘单? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮蹦渣,結(jié)果婚禮上哄芜,老公的妹妹穿的比我還像新娘。我一直安慰自己柬唯,他們只是感情好认臊,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著锄奢,像睡著了一般失晴。 火紅的嫁衣襯著肌膚如雪剧腻。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼义矛,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了盟萨?” 一聲冷哼從身側(cè)響起凉翻,我...
- 正文 年R本政府宣布先蒋,位于F島的核電站骇钦,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏竞漾。R本人自食惡果不足惜眯搭,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望业岁。 院中可真熱鬧鳞仙,春花似錦、人聲如沸叨襟。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽糊闽。三九已至梳玫,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間右犹,已是汗流浹背提澎。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- #import#import "FKViewController.h" @implementation FKVie...
- 1君编、設(shè)置UILabel行間距 NSMutableAttributedString* attrString = [[...
- 1跨嘉、設(shè)置UILabel行間距 NSMutableAttributedString* attrString = [[...