你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS開辟中經常使用的各類動畫、頁面切面後果

iOS開辟中經常使用的各類動畫、頁面切面後果

編輯:IOS開發綜合

明天重要用到的動畫類是CALayer下的CATransition至於各類動畫類中若何繼續的在這也不做贅述,網上的材料是一抓一年夜把。好空話少說切入明天的正題。

  一.封裝動畫辦法

    1.用CATransition完成動畫的封裝辦法以下,每句代碼是何意思,請看正文之。

#pragma CATransition動畫完成
- (void) transitionWithType:(NSString *) type WithSubtype:(NSString *) subtype ForView : (UIView *) view
{
//創立CATransition對象
CATransition *animation = [CATransition animation];
//設置活動時光
animation.duration = DURATION;
//設置活動type
animation.type = type;
if (subtype != nil) {
//設置子類
animation.subtype = subtype;
}
//設置活動速度
animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
[view.layer addAnimation:animation forKey:@"animation"];
} 

    代碼解釋:

      CATransition經常使用的屬性以下:

        duration:設置動畫時光

        type:稍後上面會具體的引見活動類型

        subtype:和type婚配應用,指定活動的偏向,上面也會具體引見

        timingFunction :動畫的活動軌跡,用於變更終點和起點之間的插值盤算,抽象點說它決議了動畫運轉的節拍,好比是

                 平均變更(雷同時光變更量雷同)照樣先快後慢,先慢後快照樣先慢再快再慢.    

               * 動畫的開端與停止的快慢,有五個預置分離為(下同):

                   * kCAMediaTimingFunctionLinear 線性,即勻速

                   * kCAMediaTimingFunctionEaseIn 先慢後快

                   * kCAMediaTimingFunctionEaSEOut 先快後慢

                  * kCAMediaTimingFunctionEaseInEaSEOut 先慢後快再慢

                  * kCAMediaTimingFunctionDefault 現實後果是動畫中央比擬快.

   2.用UIView的block回調完成動畫的代碼封裝 

#pragma UIView完成動畫
- (void) animationWithView : (UIView *)view WithAnimationTransition : (UIViewAnimationTransition) transition
{
[UIView animateWithDuration:DURATION animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:transition forView:view cache:YES];
}];
}

    3.轉變View的配景圖,便於切換時不雅察

#pragma 給View添加配景圖
-(void)addBgImageWithImageName:(NSString *) imageName
{
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:imageName]];
} 

  二.挪用下面的辦法完成我們想要的動畫

    1.我們在View上添加多個Button,給分歧的Button設置分歧的Tag值,然後再ViewController中綁定統一個辦法,點擊分歧的button完成分歧的頁面切換後果。storyBoard上的控件後果以下圖所示:


    2.上面我們就開端編寫點擊button要回調的辦法

      (1).界說列舉來標示按鈕所對應的動畫類型,代碼以下:

typedef enum : NSUInteger {
Fade = , //淡入淡出
Push, //推擠
Reveal, //揭開
MoveIn, //籠罩
Cube, //立方體
SuckEffect, //吮吸
OglFlip, //翻轉
RippleEffect, //波紋
PageCurl, //翻頁
PageUnCurl, //反翻頁
CameraIrisHollowOpen, //開鏡頭
CameraIrisHollowClose, //關鏡頭
CurlDown, //下翻頁
CurlUp, //上翻頁
FlipFromLeft, //左翻轉
FlipFromRight, //右翻轉
} AnimationType; 

    (2),獲得Button的Tag值:

UIButton *button = sender;
AnimationType animationType = button.tag; 

    (3).每次點擊button都轉變subtype的值,包含上,左,下,右

NSString *subtypeString;
switch (_subtype) {
case :
subtypeString = kCATransitionFromLeft;
break;
case :
subtypeString = kCATransitionFromBottom;
break;
case :
subtypeString = kCATransitionFromRight;
break;
case :
subtypeString = kCATransitionFromTop;
break;
default:
break;
}
_subtype += ;
if (_subtype > ) {
_subtype = ;
} 

    (4),經由過程switch聯合上邊的列舉來斷定是誰人按鈕點擊的

switch (animationType)
{
//各類Case,此處代碼上面會給出 
}

   3.挪用我們封裝的活動辦法,來完成動畫後果

    (1),淡化後果

case Fade:
[self transitionWithType:kCATransitionFade WithSubtype:subtypeString ForView:self.view];
break; 

    (2).Push後果

case Push:
[self transitionWithType:kCATransitionPush WithSubtype:subtypeString ForView:self.view];
break;

     後果以下:

 

    (3).揭開後果:

case Reveal:
[self transitionWithType:kCATransitionReveal WithSubtype:subtypeString ForView:self.view];
break; 

    後果圖以下:

  

    (4).籠罩後果

case MoveIn:
[self transitionWithType:kCATransitionMoveIn WithSubtype:subtypeString ForView:self.view];
break;

      後果圖以下:

   (5).立方體後果

case Cube:
[self transitionWithType:@"cube" WithSubtype:subtypeString ForView:self.view];
break; 

    後果以下:

   

    (6).吮吸後果

case SuckEffect:
[self transitionWithType:@"suckEffect" WithSubtype:subtypeString ForView:self.view];
break; 

      後果以下:

    (7).翻轉後果

case OglFlip:
[self transitionWithType:@"oglFlip" WithSubtype:subtypeString ForView:self.view];
break; 

    後果圖以下:

    8.波紋後果

case RippleEffect:
[self transitionWithType:@"rippleEffect" WithSubtype:subtypeString ForView:self.view];
break;  

 

    (9).翻頁和反翻頁後果

case PageCurl:
[self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];
break;
case PageUnCurl:
[self transitionWithType:@"pageUnCurl" WithSubtype:subtypeString ForView:self.view];
break; 

  

    (10).相機翻開後果

case CameraIrisHollowOpen:
[self transitionWithType:@"cameraIrisHollowOpen" WithSubtype:subtypeString ForView:self.view];
break;
case CameraIrisHollowClose:
[self transitionWithType:@"cameraIrisHollowClose" WithSubtype:subtypeString ForView:self.view];
break; 

  (11),挪用下面封裝的第二個動畫辦法

case CurlDown:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlDown];
break;
case CurlUp:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlUp];
break;
case FlipFromLeft:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromLeft];
break;
case FlipFromRight:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromRight];
break;

以上內容是針對IOS開辟中經常使用的各類動畫、頁面切面後果的相干引見,願望對年夜家有所贊助!

【iOS開辟中經常使用的各類動畫、頁面切面後果】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved