IOS中各種動畫特效的實現

第一類動畫特效:
這類特效有四種,在UIView中就可以實現,分別爲CurlDown,CurlUp,FilpFromLeft,FilpFromRight。在視圖切換之前設置UIView,如下:

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

    [UIView setAnimationDuration:0.5];//設置動畫持續時間;

    [UIView setAnimationDelegate:self];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

接下來設置動畫特效,有四種特效可供選擇:

 

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

[UIView setAnimationTransition:UIViewAnimationTransitionFilpFromLeft forView:self.view cache:YES];

[UIView setAnimationTransition:UIViewAnimationTransitionFilpFromRight forView:self.view cache:YES];

之後就可以切換view了,最後執行動畫:

 

[UIView commitAnimations];


第二類動畫特效:

這類動畫特效需要用到QuartzCore.framework,單擊工程,點擊Build Phases,找到Link Binary With Libraries,點擊下面的+號,找到QuartzCore.framework添加即可。

同樣,在view切換之前需要做一些設置:

 

    CATransition *animation = [CATransition animation]; //聲明動畫對象;

    animation.delegate = self;

    animation.duration = kDuration;//設置動畫持續時間;

    animation.timingFunction = UIViewAnimationCurveEaseInOut;

然後就可以選擇動畫類型,大概有十二種動畫:

 

animation.type = kCATransitionFade;

animation.type = kCATransitionPush;

animation.type = kCATransitionReveal;

animation.type = kCATransitionMoveIn;

animation.type = @"cube";

animation.type = @"suckEffect";

animation.type = @"oglFlip";

animation.type = @"rippleEffect";

animation.type = @"pageCurl";

animation.type = @"pageUnCurl";

animation.type = @"cameraIrisHollowOpen";

animation.type = @"cameraIrisHollowClose";

任選其中一種。同時也可以設置animation的subtype,用以設置動畫運行的方向,如:

 

animation.subtype = kCATransitionFromLeft;

animation.subtype = kCATransitionFromBottom;

animation.subtype = kCATransitionFromRight;

animation.subtype = kCATransitionFromTop;

之後是切換view,最後還要添加一句代碼:

 

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


發佈了28 篇原創文章 · 獲贊 2 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章