2UIView動畫
2.1概述
UIView視圖的動畫功能周崭,可以使在更新或切換視圖時有放緩節(jié)奏柳譬、產(chǎn)生流暢的動畫效果,進而改善用戶體驗续镇。UIView可以產(chǎn)生動畫效果的變化包括:
?位置變化:在屏幕上移動視圖美澳。
?大小變化:改變視圖框架(frame)和邊界。
?拉伸變化:改變視圖內(nèi)容的延展區(qū)域摸航。
?改變透明度:改變視圖的alpha值制跟。
?改變狀態(tài):隱藏或顯示狀態(tài)。
?改變視圖層次順序:視圖哪個前哪個后酱虎。
?旋轉(zhuǎn):即任何應(yīng)用到視圖上的仿射變換(transform)凫岖。
UIKit直接將動畫集成到UIView類中,實現(xiàn)簡單動畫的創(chuàng)建過程逢净。UIView類定義了幾個內(nèi)在支持動畫的屬性聲明,當這些屬性發(fā)生改變時,視圖為其變化過程提供內(nèi)建的動畫支持爹土。
執(zhí)行動畫所需要的工作由UIView類自動完成甥雕,但仍要在希望執(zhí)行動畫時通知視圖,為此需要將改變屬性的代碼包裝到一個代碼塊中胀茵。
2.2UIView動畫簡單創(chuàng)建方法
- (void)buttonPressed
{
//交換本視圖控制器中2個view位置
[self.viewexchangeSubviewAtIndex:0 withSubviewAtIndex:1];
//UIView開始動畫社露,第一個參數(shù)是動畫的標識,第二個參數(shù)附加的應(yīng)用程序信息用來傳遞給動畫代理消息
[UIViewbeginAnimations:@"View Flip" context:nil];
//動畫持續(xù)時間
[UIViewsetAnimationDuration:1.25];
//設(shè)置動畫的回調(diào)函數(shù)琼娘,設(shè)置后可以使用回調(diào)方法
[UIViewsetAnimationDelegate:self];
//設(shè)置動畫曲線峭弟,控制動畫速度
[UIView?setAnimationCurve: UIViewAnimationCurveEaseInOut];
//設(shè)置動畫方式,并指出動畫發(fā)生的位置
[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view?cache:YES];
//提交UIView動畫
[UIViewcommitAnimations];
}
- (void)viewDidLoad
{
[super viewDidLoad];
//主要功能通過UIView動畫完成2個試圖控制器的切換
self.blueController =[[BlueViewController alloc] initWithNibName:nil bundle:nil];
//設(shè)置導(dǎo)航控制器view的大小占整個屏幕
[self.blueController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
self.yellowController =[[YellowController alloc]initWithNibName:nil bundle:nil ];
[self.yellowController.view setFrame:CGRectMake(0, 0,self.view.frame.size.width , self.view.frame.size.height)];
//將2個控制器view插入到目前導(dǎo)航控制器視圖上脱拼,yellowController后插入瞒瘸,顯示在最前面
[self.viewinsertSubview:self.blueController.view atIndex:0];
[self.viewinsertSubview:self.yellowController.view atIndex:1];
//創(chuàng)建導(dǎo)航控制器右按鈕,按鈕名字叫next
//添加buttonPressed事件
self.rightBarItem =[[UIBarButtonItem alloc] initWithTitle:@"next" style:UIBarButtonItemStylePlaintarget:self action:@selector(buttonPressed)];
//將按鈕添加到導(dǎo)航控制器默認右按鈕上
self.navigationItem.rightBarButtonItem = self.rightBarItem;
}
有個問題:如果動畫不放在按鈕事件中熄浓,直接放到viewDidLoad里情臭,程序首先執(zhí)行這個controller,這時動畫是不會顯示的赌蔑。
原因:出現(xiàn)這個問題是因為開機時候系統(tǒng)有個動畫俯在,系統(tǒng)動畫和這個動畫重復(fù)了。
解決方案:
1娃惯、將動畫寫在按鈕事件中
2跷乐、利用定時器。
轉(zhuǎn):UIView動畫更具體講解趾浅;http://wsqwsq000.iteye.com/blog/1189183
2.3創(chuàng)建UIView動畫(塊)——(指過渡效果的動畫)
2.3.1一.基本方式:使用UIView類的UIViewAnimation擴展
UIView動畫是成塊運行的愕提。發(fā)出beginAnimations:context:請求標志著動畫塊的開始;commitAnimations標志著動畫塊的結(jié)束潮孽。把這兩個類方法發(fā)送給UIView而不是發(fā)送給單獨的視圖揪荣。在這兩個調(diào)用之間的可定義動畫的展現(xiàn)方式并更新視圖。函數(shù)說明:
//開始準備動畫
+ (void)beginAnimations:(NSString *)animationID context:(void*)context;
//運行動畫
+ (void)commitAnimations;
具體二段動畫代碼:
[UIView beginAnimations:nil context:nil];
//setAnimationCurve來定義動畫加速或減速方式
[UIView?setAnimaitonCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:2.7];//動畫時長
[UIView setAnimationTransition:transitionforView:self.view cache:YES];
// operation>>>
[self.view exchangeSubviewAtIndex:0withSubviewAtIndex:1];
// end<<<<<
[UIView commitAnimations];
CGContextRef context = UIGraphicsGetCurrentContext();//返回當前視圖堆棧頂部的圖形上下文
[UIView beginAnimations:nil context:context];
[UIView setAnimaitonCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
// View changes go here
[contextView setAlpha:0.0f];
[UIView commitAnimations];
其中transition取值范圍:UIView類本身提供四種過渡效果
UIViewAnimationTransitionNone正常
UIViewAnimationTransitionFlipFromLeft從左向右翻
UIViewAnimationTransitionFlipFromRight從右向左翻
UIViewAnimationTransitionCurlUp從下向上卷
UIViewAnimationTransitionCurlDown從上向下卷
2.3.2二.block方式:使用UIView類的UIViewAnimation WithBlocks擴展
要用到的函數(shù)有:
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay
options:(UIViewAnimationOptions)options animations:(void(^)(void))animations
completion:(void(^)(BOOL finished))completion
__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);
//間隔,延遲,動畫參數(shù)(好像沒用?),界面更改塊,結(jié)束塊
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void(^)(void))animations
completion:(void(^)(BOOL finished))completion
__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);
// delay = 0.0, options = 0
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void(^)(void))animations
__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);
// delay = 0.0, options = 0, completion =
NULL
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration
options:(UIViewAnimationOptions)options animations:(void(^)(void))animations
completion:(void(^)(BOOL finished))completion
__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView
duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options
completion:(void(^)(BOOL finished))completion
__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);
// toView added to fromView.superview,
fromView removed from its superview界面替換,這里的options參數(shù)有效
2.3.3三.core方式:使用CATransition類
iPhone還支持Core Animation作為其QuartzCore架構(gòu)的一部分往史,CA API為iPhone應(yīng)用程序提供了高度靈活的動畫解決方案仗颈。但是須知:CATransition只針對圖層,不針對視圖椎例。圖層是Core Animation與每個UIView產(chǎn)生聯(lián)系的工作層面挨决。使用Core Animation時,應(yīng)該將CATransition應(yīng)用到視圖的默認圖層([myView layer])而不是視圖本身订歪。
使用CATransition類實現(xiàn)動畫脖祈,只需要建立一個Core Animation對象,設(shè)置它的參數(shù)刷晋,然后把這個帶參數(shù)的過渡添加到圖層即可盖高。
使用要引入QuartzCore.framework代碼
#import
示例代碼:
CATransition *transition = [CATransition
animation];
transition.duration =0.7;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;//{kCATransitionMoveIn, kCATransitionPush,kCATransitionReveal, kCATransitionFade};
//更多私有{@"cube",@"suckEffect",@"oglFlip",@"rippleEffect",@"pageCurl",@"pageUnCurl",@"cameraIrisHollowOpen",@"cameraIrisHollowClose"};
transition.subtype =
kCATransitionFromLeft;//{kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop,kCATransitionFromBottom};
transition.delegate= self;
[self.view.layer addAnimation:transition forKey:nil];
//要做的
[self.view exchangeSubviewAtIndex:1withSubviewAtIndex:0];
CATransition動畫使用了類型type和子類型subtype兩個概念慎陵。type屬性指定了過渡的種類(淡化、推擠喻奥、揭開席纽、覆蓋)。subtype設(shè)置了過渡的方向(從上撞蚕、下润梯、左、右)甥厦。另外纺铭,CATransition私有的動畫類型有(立方體、吸收刀疙、翻轉(zhuǎn)舶赔、波紋、翻頁庙洼、反翻頁顿痪、鏡頭開、鏡頭關(guān))油够。
2.4API簡介
areAnimationsEnabled
返回一個布爾值表示動畫是否結(jié)束蚁袭。
+ (BOOL)areAnimationsEnabled
返回值
如果動畫結(jié)束返回YES,否則NO石咬。
beginAnimations:context:
開始一個動畫塊
+ (void)beginAnimations:(NSString*)animationID context:(void *)context
參數(shù)
animationID
動畫塊內(nèi)部應(yīng)用程序標識用來傳遞給動畫代理消息-這個選擇器運用setAnimationWillStartSelector:和setAnimationDidStopSelector:方法來設(shè)置揩悄。
context
附加的應(yīng)用程序信息用來傳遞給動畫代理消息-這個選擇器使用setAnimationWillStartSelector:和setAnimationDidStopSelector:方法。
討論
這個值改變是因為設(shè)置了一些需要在動畫塊中產(chǎn)生動畫的屬性鬼悠。動畫塊可以被嵌套删性。如果在沒有在動畫塊中調(diào)用那么setAnimation類方法將什么都不做。使用beginAnimations:context:來開始一個動畫塊并用commitAnimations類方法來結(jié)束一個動畫塊焕窝。
commitAnimations
結(jié)束一個動畫塊并開始當他在動畫塊外時蹬挺。
+ (void)commitAnimations
討論
如果當前的動畫塊是最外層的動畫塊,當應(yīng)用程序返回到循環(huán)運行時開始動畫塊它掂。動畫在一個獨立的線程中所有應(yīng)用程序不會中斷巴帮。使用這個方法,多個動畫可以被實現(xiàn)虐秋。查看setAnimationBeginsFromCurrentState:來了解如果開始一個動畫當另外一個動畫在播放的時候榕茧。
layerClass
返回類用來創(chuàng)建這一個本類的layer實例對象。
+ (Class)layerClass
返回值
一個用來創(chuàng)建視圖layer的類
討論
重寫子類來指定一個自定義類用來顯示客给。當在創(chuàng)建視圖layer時候調(diào)用用押。默認的值是CALayer類對象。
setAnimationBeginsFromCurrentState:
設(shè)置動畫從當前狀態(tài)開始播放靶剑。
+(void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState
參數(shù)
fromCurrentState
YES如果動畫需要從他們當前狀態(tài)開始播放蜻拨。否則為NO池充。
討論
如果設(shè)置為YES那么當動畫在運行過程中,當前視圖的位置將會作為新的動畫的開始狀態(tài)缎讼。如果設(shè)置為NO纵菌,當前動畫結(jié)束前新動畫將使用視圖最後狀態(tài)的位置作為開始狀態(tài)。這個方法將不會做任何事情如果動畫沒有運行或者沒有在動畫塊外調(diào)用休涤。使用beginAnimations:context:類方法來開始并用commitAnimations類方法來結(jié)束動畫塊。默認值是NO笛辟。
setAnimationCurve:
設(shè)置動畫塊中的動畫屬性變化的曲線功氨。
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve
討論
動畫曲線是動畫運行過程中相對的速度。如果在動畫塊外調(diào)用這個方法將會無效手幢。使用beginAnimations:context:類方法來開始動畫塊并用commitAnimations來結(jié)束動畫塊捷凄。默認動畫曲線的值是UIViewAnimationCurveEaseInOut。
setAnimationDelay:
在動畫塊中設(shè)置動畫的延遲屬性(以秒為單位)
+(void)setAnimationDelay:(NSTimeInterval)delay
討論
這個方法在動畫塊外調(diào)用無效围来。使用beginAnimations:context:類方法開始一個動畫塊并用commitAnimations類方法結(jié)束動畫塊跺涤。默認的動畫延遲是0.0秒。
setAnimationDelegate:
設(shè)置動畫消息的代理监透。
+ (void)setAnimationDelegate:(id)delegate
參數(shù)
delegate
你可以用setAnimationWillStartSelector:和setAnimationDidStopSelector:方法來設(shè)置接收代理消息的對象桶错。
討論
這個方法在動畫塊外沒有任何效果。使用beginAnimations:context:類方法開始一個動畫塊并用commitAnimations類方法結(jié)束一個動畫塊胀蛮。默認值是nil
setAnimationDidStopSelector:
設(shè)置消息給動畫代理當動畫停止的時候院刁。
+(void)setAnimationDidStopSelector:(SEL)selector
參數(shù)
selector
當動畫結(jié)束的時候發(fā)送給動畫代理。默認值是NULL粪狼。這個選擇者須有下面方法的簽名:animationFinished:(NSString *)animationID
finished:(BOOL)finished context:(void *)context退腥。
animationID
一個應(yīng)用程序提供的標識符。和傳給beginAnimations:context:相同的參數(shù)再榄。這個參數(shù)可以為空狡刘。
finished
如果動畫在停止前完成那返回YES;否則就是NO困鸥。
context
一個可選的應(yīng)用程序內(nèi)容提供者嗅蔬。和beginAnimations:context:方法相同的參數(shù)∥迅铮可以為空购城。
討論
這個方法在動畫塊外沒有任何效果。使用beginAnimations:context:類方法來開始一個動畫塊并用commitAnimations類方法結(jié)束虐译。默認值是NULL瘪板。
setAnimationDuration:
設(shè)置動畫塊中的動畫持續(xù)時間(用秒)
+(void)setAnimationDuration:(NSTimeInterval)duration
參數(shù)
duration
一段動畫持續(xù)的時間。
討論
這個方法在動畫塊外沒有效果漆诽。使用beginAnimations:context:類方法來開始一個動畫塊并用commitAnimations類方法來結(jié)束一個動畫塊侮攀。默認值是0.2锣枝。
setAnimationRepeatAutoreverses:設(shè)置動畫塊中的動畫效果是否自動重復(fù)播放。
+(void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses
參數(shù)
repeatAutoreverses
如果動畫自動重復(fù)就是YES否則就是NO兰英。
討論
自動重復(fù)是當動畫向前播放結(jié)束後再重頭開始播放撇叁。使用setAnimationRepeatCount:類方法來指定動畫自動重播的時間。如果重復(fù)數(shù)為0或者在動畫塊外那將沒有任何效果畦贸。使用beginAnimations:context:類方法來開始一個動畫塊并用commitAnimations方法來結(jié)束一個動畫塊陨闹。默認值是NO。
setAnimationRepeatCount:
設(shè)置動畫在動畫模塊中的重復(fù)次數(shù)
+(void)setAnimationRepeatCount:(float)repeatCount
參數(shù)
repeatCount
動畫重復(fù)的次數(shù)薄坏,這個值可以是分數(shù)趋厉。
討論
這個屬性在動畫塊外沒有任何作用。使用beginAnimations:context:類方法來開始一個動畫塊并用commitAnimations類方法來結(jié)束胶坠。默認動畫不循環(huán)君账。
setAnimationsEnabled:
設(shè)置是否激活動畫
+ (void)setAnimationsEnabled:(BOOL)enabled
參數(shù)
enabled
如果是YES那就激活動畫;否則就是NO
討論
當動畫參數(shù)沒有被激活那么動畫屬性的改變將被忽略沈善。默認動畫是被激活的乡数。
setAnimationStartDate:
設(shè)置在動畫塊內(nèi)部動畫屬性改變的開始時間
+ (void)setAnimationStartDate:(NSDate*)startTime
參數(shù)
startTime
一個開始動畫的時間
討論
使用beginAnimations:context:類方法來開始一個動畫塊并用commitAnimations類方法來結(jié)束動畫塊。默認的開始時間值由CFAbsoluteTimeGetCurrent方法來返回闻牡。
setAnimationTransition:forView:cache:在動畫塊中為視圖設(shè)置過渡
+ (void)setAnimationTransition:(UIViewAnimationTransition)transitionforView:(UIView *)view cache:(BOOL)cache
參數(shù)
transition
把一個過渡效果應(yīng)用到視圖中净赴。可能的值定義在UIViewAnimationTransition中澈侠。
view
需要過渡的視圖對象劫侧。
cache
如果是YES,那么在開始和結(jié)束圖片視圖渲染一次并在動畫中創(chuàng)建幀哨啃;否則烧栋,視圖將會在每一幀都渲染。例如緩存拳球,你不需要在視圖轉(zhuǎn)變中不停的更新审姓,你只需要等到轉(zhuǎn)換完成再去更新視圖。
討論
如果你想要在轉(zhuǎn)變過程中改變視圖的外貌祝峻。舉個例子魔吐,文件從一個視圖到另一個視圖,然後使用一個UIView子類的容器視圖莱找,如下:
1.Begin an animation block.
2.Set the transition on the container view.
3.Remove the subview from the containerview.
4.Add the new subview to the containerview.
5.Commit the animation block.
1.開始一個動畫塊酬姆。2.在容器視圖中設(shè)置轉(zhuǎn)換。3.在容器視圖中移除子視圖奥溺。4.在容器視圖中添加子視圖辞色。5.結(jié)束動畫塊。
setAnimationWillStartSelector:
當動畫開始時發(fā)送一條消息到動畫代理
+(void)setAnimationWillStartSelector:(SEL)selector
參數(shù)
selector
在動畫開始前向動畫代理發(fā)送消息浮定。默認值是NULL相满。這個selector必須由和beginAnimations:context:方法相同的參數(shù)层亿,一個任選的程序標識和內(nèi)容。這些參數(shù)都可以是nil立美。
討論
這個方法在動畫塊外沒有任何作用匿又。使用beginAnimations:context:類方法來開始一個動畫塊并用commitAnimations類方法來結(jié)束。
2.5簡單動畫效果示例
2.5.1簡單移動
imageView.transform =CGAffineTransformIdentity;
imageView.frame=CGRectMake(0, 100, 320,320);
[UIView beginAnimations:@"clearmemory"context:imageView];
[UIView setAnimationDelegate:self];
[UIViewsetAnimationDidStopSelector:@selector(enablebutton)];
imageView.frame=CGRectMake(34, 0, 320,320);
[UIView commitAnimations];
2.5.2動畫曲線
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseIn];
//UIViewAnimationCurveEaseInOut, ? ? ? ? // slow at beginningand end
//UIViewAnimationCurveEaseIn,? ? ? ? ? ? // slowat beginning
//UIViewAnimationCurveEaseOut, ? ? ? ? ? // slow atend
//UIViewAnimationCurveLinear
//恒定速度
[UIViewsetAnimationDidStopSelector:@selector(enablebutton:)];
imageView.frame=CGRectMake(22, 0, 320, 320);
[UIView commitAnimations];
2.5.3反向重復(fù)
[UIViewbeginAnimations:@"animation3" context:imageView1];
[UIViewsetAnimationCurve:UIViewAnimationCurveLinear];
[UIViewsetAnimationDuration:1.0];
[UIViewsetAnimationRepeatAutoreverses:YES];
[UIViewsetAnimationRepeatCount:10];
[UIViewsetAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(enablebutton:)];
imageView1.alpha=0;
[UIViewcommitAnimations];
2.5.4延時建蹄,緩入碌更,緩出
[UIView beginAnimations:nilcontext:nil];
[UIViewsetAnimationDelay:0.5];
[UIViewsetAnimationDuration:1.5];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseIn];
[UIViewsetAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:2];
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationDidStopSelector:@selector(enablebutton:)];
imageView.frame=CGRectMake(120, 0, 200, 200);
[UIView commitAnimations];
//緩出
[UIView beginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseOut];
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationDidStopSelector:@selector(enablebutton:)];
imageView.frame=CGRectMake(235, 144, 200 , 200);
[UIView commitAnimations];
2.5.5放大
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationCurve:UIViewAnimationCurveLinear];
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationDidStopSelector:@selector(enablebutton:)];
imageView.transform=CGAffineTransformMakeScale(2,2);
[UIView commitAnimations];
//旋轉(zhuǎn)放大這里用到179.9是因為你不管前面加-+都是逆時針
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationCurve:UIViewAnimationCurveLinear];
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationDidStopSelector:@selector(enablebutton:)];
CGAffineTransformtranform1=CGAffineTransformMakeScale(1, 1);
CGAffineTransformtranform3=CGAffineTransformMakeTranslation(200, 200);
CGAffineTransformtranform2=CGAffineTransformMakeRotation(179.9*M_PI/180.0);
imageView.transform=CGAffineTransformConcat(tranform1, tranform3);
[UIView commitAnimations];
2.5.6平移旋轉(zhuǎn)
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationDidStopSelector:@selector(enablebutton:)];
CGAffineTransformtranform1=CGAffineTransformMakeTranslation(-200, 0);
// CGAffineTransformtranform2= CGAffineTransformMakeRotation(179.9*M_PI/180.0);
imageView.transform=CGAffineTransformRotate(tranform1, 359.9*M_PI/180.0);
[UIView commitAnimations];
2.5.7翻轉(zhuǎn)
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseIn];
[UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFromRightforView:self.viewcache:YES];
//UIViewAnimationTransitionFlipFromLeft從左往右翻
//UIViewAnimationTransitionFlipFromRight從右往左翻
//UIViewAnimationTransitionCurlUp從上往下翻
//UIViewAnimationTransitionCurlDown從下往上翻
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationDidStopSelector:@selector(enablebutton:)];
imageView.hidden=YES;
imageView1.hidden=NO;
[UIView commitAnimations];
2.5.8淡入淡出
CATransition *animation = [CATransitionanimation];
animation.duration = 0.75f; //動畫時長
animation.timingFunction =[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
animation.delegate = self;
animation.type = kCATransitionFade; //過度效果
//kCATransitionFade淡入淡出
//kCATransitionMoveIn移入移出
//kCATransitionPush壓入推出
//kCATransitionReveal覆蓋移除
animation.subtype=kCATransitionFromLeft;
//kCATransitionFromRight從左
//kCATransitionFromLeft從右
//kCATransitionFromTop從上
//kCATransitionFromBottom從下
[self.view.layer addAnimation:animationforKey:@"animation"];
imageView.hidden=YES;
imageView1.hidden=NO;
-(void)enablebutton:(id)sender
{
imageView.transform=CGAffineTransformIdentity;
imageView.frame=CGRectMake(0,0, 200, 200);
//btn.enabled=NO;
}
2.5.9點擊縮略圖到大圖的過場動畫
CGRectframe = [smallImgView.superviewconvertRect: smallImgView.frametoView:self.window];
//后續(xù)有入場動畫
_coverView=
[[UIScrollViewalloc]initWithFrame:frame];
//增加入場動畫
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:0.25];
_coverView.frame=CGRectMake(0,0,ESScrnW,ESScrnH);
[UIViewcommitAnimations];