国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

2019-10-21 18:56:57
字體:
供稿:網(wǎng)友
這篇文章主要介紹了iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建,以關(guān)鍵幀動(dòng)畫作為重要知識(shí)點(diǎn)進(jìn)行講解,需要的朋友可以參考下
 

一、簡單介紹

CAPropertyAnimation的子類

屬性解析:

fromValue:keyPath相應(yīng)屬性的初始值

toValue:keyPath相應(yīng)屬性的結(jié)束值

隨著動(dòng)畫的進(jìn)行,在長度為duration的持續(xù)時(shí)間內(nèi),keyPath相應(yīng)屬性的值從fromValue漸漸地變?yōu)閠oValue

如果fillMode=kCAFillModeForwards和removedOnComletion=NO,那么在動(dòng)畫執(zhí)行完畢后,圖層會(huì)保持顯示動(dòng)畫執(zhí)行后的狀態(tài)。但在實(shí)質(zhì)上,圖層的屬性值還是動(dòng)畫執(zhí)行前的初始值,并沒有真正被改變。

比如,CALayer的position初始值為(0,0),CABasicAnimation的fromValue為(10,10),toValue為(100,100),雖然動(dòng)畫執(zhí)行完畢后圖層保持在(100,100)這個(gè)位置,實(shí)質(zhì)上圖層的position還是為(0,0)

 

二、平移動(dòng)畫

代碼示例:

復(fù)制代碼代碼如下:

//
//  YYViewController.m
//  07-核心動(dòng)畫(基礎(chǔ)動(dòng)畫)
//
//  Created by apple on 14-6-21.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

 

#import "YYViewController.h"

@interface YYViewController ()
@property(nonatomic,strong)CALayer *myLayer;
@end


復(fù)制代碼代碼如下:

@implementation YYViewController

 

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //創(chuàng)建layer
    CALayer *myLayer=[CALayer layer];
    //設(shè)置layer的屬性
    myLayer.bounds=CGRectMake(0, 0, 50, 80);
    myLayer.backgroundColor=[UIColor yellowColor].CGColor;
    myLayer.position=CGPointMake(50, 50);
    myLayer.anchorPoint=CGPointMake(0, 0);
    myLayer.cornerRadius=20;
    //添加layer
    [self.view.layer addSublayer:myLayer];
    self.myLayer=myLayer;
}

//設(shè)置動(dòng)畫(基礎(chǔ)動(dòng)畫)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.創(chuàng)建核心動(dòng)畫
    //    CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:<#(NSString *)#>]
    CABasicAnimation *anima=[CABasicAnimation animation];
    
    //1.1告訴系統(tǒng)要執(zhí)行什么樣的動(dòng)畫
    anima.keyPath=@"position";
    //設(shè)置通過動(dòng)畫,將layer從哪兒移動(dòng)到哪兒
    anima.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)];
    anima.toValue=[NSValue valueWithCGPoint:CGPointMake(200, 300)];
    
    //1.2設(shè)置動(dòng)畫執(zhí)行完畢之后不刪除動(dòng)畫
    anima.removedOnCompletion=NO;
    //1.3設(shè)置保存動(dòng)畫的最新狀態(tài)
    anima.fillMode=kCAFillModeForwards;

    //2.添加核心動(dòng)畫到layer
    [self.myLayer addAnimation:anima forKey:nil];

}
  @end


代碼說明:

 

 第42行設(shè)置的keyPath是@"position",說明要修改的是CALayer的position屬性,也就是會(huì)執(zhí)行平移動(dòng)畫

 第44,45行,這里的屬性接收的時(shí)id類型的參數(shù),因此并不能直接使用CGPoint這種結(jié)構(gòu)體類型,而是要先包裝成NSValue對(duì)象后再使用。

 默認(rèn)情況下,動(dòng)畫執(zhí)行完畢后,動(dòng)畫會(huì)自動(dòng)從CALayer上移除,CALayer又會(huì)回到原來的狀態(tài)。為了保持動(dòng)畫執(zhí)行后的狀態(tài),可以加入第48,50行代碼

byValue和toValue的區(qū)別,前者是在當(dāng)前的位置上增加多少,后者是到指定的位置。
 

執(zhí)行效果:

實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

設(shè)置代理:設(shè)置動(dòng)畫的代理,可以監(jiān)聽動(dòng)畫的執(zhí)行過程,這里設(shè)置控制器為代理。

代碼示例:

復(fù)制代碼代碼如下:

#import "YYViewController.h"

 

@interface YYViewController ()
@property(nonatomic,strong)CALayer *myLayer;
@end

@implementation YYViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //創(chuàng)建layer
    CALayer *myLayer=[CALayer layer];
    //設(shè)置layer的屬性
    myLayer.bounds=CGRectMake(0, 0, 50, 80);
    myLayer.backgroundColor=[UIColor yellowColor].CGColor;
    myLayer.position=CGPointMake(50, 50);
    myLayer.anchorPoint=CGPointMake(0, 0);
    myLayer.cornerRadius=20;
    //添加layer
    [self.view.layer addSublayer:myLayer];
    self.myLayer=myLayer;
}

//設(shè)置動(dòng)畫(基礎(chǔ)動(dòng)畫)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.創(chuàng)建核心動(dòng)畫
    //    CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:<#(NSString *)#>]
    CABasicAnimation *anima=[CABasicAnimation animation];
    
    //1.1告訴系統(tǒng)要執(zhí)行什么樣的動(dòng)畫
    anima.keyPath=@"position";
    //設(shè)置通過動(dòng)畫,將layer從哪兒移動(dòng)到哪兒
    anima.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)];
    anima.toValue=[NSValue valueWithCGPoint:CGPointMake(200, 300)];
    
    //1.2設(shè)置動(dòng)畫執(zhí)行完畢之后不刪除動(dòng)畫
    anima.removedOnCompletion=NO;
    //1.3設(shè)置保存動(dòng)畫的最新狀態(tài)
    anima.fillMode=kCAFillModeForwards;
    anima.delegate=self;
    //打印
    NSString *str=NSStringFromCGPoint(self.myLayer.position);
    NSLog(@"執(zhí)行前:%@",str);
    
    //2.添加核心動(dòng)畫到layer
    [self.myLayer addAnimation:anima forKey:nil];

}

-(void)animationDidStart:(CAAnimation *)anim
{
    NSLog(@"開始執(zhí)行動(dòng)畫");
}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    //動(dòng)畫執(zhí)行完畢,打印執(zhí)行完畢后的position值
    NSString *str=NSStringFromCGPoint(self.myLayer.position);
    NSLog(@"執(zhí)行后:%@",str);
}

@end


打印position的屬性值,驗(yàn)證圖層的屬性值還是動(dòng)畫執(zhí)行前的初始值{50,50},并沒有真正被改變?yōu)閧200,300}。

 

實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

 

三、縮放動(dòng)畫

實(shí)現(xiàn)縮放動(dòng)畫的代碼示例:

復(fù)制代碼代碼如下:

//
//  YYViewController.m
//  08-核心動(dòng)畫平移
//
//  Created by apple on 14-6-21.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

 

#import "YYViewController.h"

@interface YYViewController ()
@property(nonatomic,strong)CALayer *myLayer;
@end


復(fù)制代碼代碼如下:

@implementation YYViewController

 

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //創(chuàng)建layer
    CALayer *myLayer=[CALayer layer];
    //設(shè)置layer的屬性
    myLayer.bounds=CGRectMake(0, 0, 150, 60);
    myLayer.backgroundColor=[UIColor yellowColor].CGColor;
    myLayer.position=CGPointMake(50, 50);
    myLayer.anchorPoint=CGPointMake(0, 0);
    myLayer.cornerRadius=40;
    //添加layer
    [self.view.layer addSublayer:myLayer];
    self.myLayer=myLayer;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.創(chuàng)建動(dòng)畫
    CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:@"bounds"];
    //1.1設(shè)置動(dòng)畫執(zhí)行時(shí)間
    anima.duration=2.0;
    //1.2設(shè)置動(dòng)畫執(zhí)行完畢后不刪除動(dòng)畫
    anima.removedOnCompletion=NO;
    //1.3設(shè)置保存動(dòng)畫的最新狀態(tài)
    anima.fillMode=kCAFillModeForwards;
    //1.4修改屬性,執(zhí)行動(dòng)畫
    anima.toValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)];
    //2.添加動(dòng)畫到layer
    [self.myLayer addAnimation:anima forKey:nil];
}

@end


實(shí)現(xiàn)效果:

 

實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

四、旋轉(zhuǎn)動(dòng)畫

代碼示例:

復(fù)制代碼代碼如下:

//
//  YYViewController.m
//  09-核心動(dòng)畫旋轉(zhuǎn)
//
//  Created by apple on 14-6-21.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

 

#import "YYViewController.h"

@interface YYViewController ()
@property(nonatomic,strong)CALayer *myLayer;
@end


復(fù)制代碼代碼如下:

@implementation YYViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //創(chuàng)建layer
    CALayer *myLayer=[CALayer layer];
    //設(shè)置layer的屬性
    myLayer.bounds=CGRectMake(0, 0, 150, 60);
    myLayer.backgroundColor=[UIColor yellowColor].CGColor;
    myLayer.position=CGPointMake(50, 50);
    myLayer.anchorPoint=CGPointMake(0, 0);
    myLayer.cornerRadius=40;
    //添加layer
    [self.view.layer addSublayer:myLayer];
    self.myLayer=myLayer;
}

 

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.創(chuàng)建動(dòng)畫
    CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:@"transform"];
    //1.1設(shè)置動(dòng)畫執(zhí)行時(shí)間
    anima.duration=2.0;
    //1.2修改屬性,執(zhí)行動(dòng)畫
    anima.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2+M_PI_4, 1, 1, 0)];
    //1.3設(shè)置動(dòng)畫執(zhí)行完畢后不刪除動(dòng)畫
    anima.removedOnCompletion=NO;
    //1.4設(shè)置保存動(dòng)畫的最新狀態(tài)
    anima.fillMode=kCAFillModeForwards;
    
    //2.添加動(dòng)畫到layer
    [self.myLayer addAnimation:anima forKey:nil];
}
@end


實(shí)現(xiàn)效果:

 

實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

補(bǔ)充:

可以通過transform(KVC)的方式來進(jìn)行設(shè)置。

代碼示例(平移):

復(fù)制代碼代碼如下:

#import "YYViewController.h"

 

@interface YYViewController ()
@property(nonatomic,strong)CALayer *myLayer;
@end


復(fù)制代碼代碼如下:

@implementation YYViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //創(chuàng)建layer
    CALayer *myLayer=[CALayer layer];
    //設(shè)置layer的屬性
    myLayer.bounds=CGRectMake(0, 0, 150, 60);
    myLayer.backgroundColor=[UIColor yellowColor].CGColor;
    myLayer.position=CGPointMake(50, 50);
    myLayer.anchorPoint=CGPointMake(0, 0);
    myLayer.cornerRadius=40;
    //添加layer
    [self.view.layer addSublayer:myLayer];
    self.myLayer=myLayer;
}

 

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.創(chuàng)建動(dòng)畫
    CABasicAnimation *anima=[CABasicAnimation animation];
    anima.keyPath=@"transform";
    //1.1設(shè)置動(dòng)畫執(zhí)行時(shí)間
    anima.duration=2.0;
    //1.2修改屬性,執(zhí)行動(dòng)畫
  
    anima.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(0, 100, 1)];
    //1.3設(shè)置動(dòng)畫執(zhí)行完畢后不刪除動(dòng)畫
    anima.removedOnCompletion=NO;
    //1.4設(shè)置保存動(dòng)畫的最新狀態(tài)
    anima.fillMode=kCAFillModeForwards;
    
    //2.添加動(dòng)畫到layer
    [self.myLayer addAnimation:anima forKey:nil];
}


實(shí)現(xiàn)效果:

 

繪制的圖形在y的方向上移動(dòng)100個(gè)單位。

實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

五、關(guān)鍵幀動(dòng)畫

1.簡單介紹

是CApropertyAnimation的子類,跟CABasicAnimation的區(qū)別是:CABasicAnimation只能從一個(gè)數(shù)值(fromValue)變到另一個(gè)數(shù)值(toValue),而CAKeyframeAnimation會(huì)使用一個(gè)NSArray保存這些數(shù)值

屬性解析:

values:就是上述的NSArray對(duì)象。里面的元素稱為”關(guān)鍵幀”(keyframe)。動(dòng)畫對(duì)象會(huì)在指定的時(shí)間(duration)內(nèi),依次顯示values數(shù)組中的每一個(gè)關(guān)鍵幀

path:可以設(shè)置一個(gè)CGPathRef/CGMutablePathRef,讓層跟著路徑移動(dòng)。path只對(duì)CALayer的anchorPoint和position起作用。如果你設(shè)置了path,那么values將被忽略

keyTimes:可以為對(duì)應(yīng)的關(guān)鍵幀指定對(duì)應(yīng)的時(shí)間點(diǎn),其取值范圍為0到1.0,keyTimes中的每一個(gè)時(shí)間值都對(duì)應(yīng)values中的每一幀.當(dāng)keyTimes沒有設(shè)置的時(shí)候,各個(gè)關(guān)鍵幀的時(shí)間是平分的

說明:CABasicAnimation可看做是最多只有2個(gè)關(guān)鍵幀的CAKeyframeAnimation

2.代碼示例

第一種方式:

代碼:

復(fù)制代碼代碼如下:

//
//  YYViewController.m
//  10-核心動(dòng)畫(關(guān)鍵幀動(dòng)畫1)
//
//  Created by apple on 14-6-21.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

 

#import "YYViewController.h"

@interface YYViewController ()
@property (weak, nonatomic) IBOutlet UIView *customView;

@end


復(fù)制代碼代碼如下:

@implementation YYViewController

 


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.創(chuàng)建核心動(dòng)畫
    CAKeyframeAnimation *keyAnima=[CAKeyframeAnimation animation];
    //平移
    keyAnima.keyPath=@"position";
    //1.1告訴系統(tǒng)要執(zhí)行什么動(dòng)畫
    NSValue *value1=[NSValue valueWithCGPoint:CGPointMake(100, 100)];
    NSValue *value2=[NSValue valueWithCGPoint:CGPointMake(200, 100)];
    NSValue *value3=[NSValue valueWithCGPoint:CGPointMake(200, 200)];
    NSValue *value4=[NSValue valueWithCGPoint:CGPointMake(100, 200)];
    NSValue *value5=[NSValue valueWithCGPoint:CGPointMake(100, 100)];
    keyAnima.values=@[value1,value2,value3,value4,value5];
    //1.2設(shè)置動(dòng)畫執(zhí)行完畢后,不刪除動(dòng)畫
    keyAnima.removedOnCompletion=NO;
    //1.3設(shè)置保存動(dòng)畫的最新狀態(tài)
    keyAnima.fillMode=kCAFillModeForwards;
    //1.4設(shè)置動(dòng)畫執(zhí)行的時(shí)間
    keyAnima.duration=4.0;
    //1.5設(shè)置動(dòng)畫的節(jié)奏
    keyAnima.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    
    //設(shè)置代理,開始—結(jié)束
    keyAnima.delegate=self;
    //2.添加核心動(dòng)畫
    [self.customView.layer addAnimation:keyAnima forKey:nil];
}

-(void)animationDidStart:(CAAnimation *)anim
{
    NSLog(@"開始動(dòng)畫");
}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    NSLog(@"結(jié)束動(dòng)畫");
}
@end


說明:這個(gè)項(xiàng)目在storyboard中拖入了一個(gè)view,并和控制器中的custom進(jìn)行了關(guān)聯(lián)。

 

效果和打印結(jié)果:

實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

補(bǔ)充:設(shè)置動(dòng)畫的節(jié)奏

實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

第二種方式(使用path)讓layer在指定的路徑上移動(dòng)(畫圓):

代碼:

復(fù)制代碼代碼如下:

#import "YYViewController.h"

 

@interface YYViewController ()
@property (weak, nonatomic) IBOutlet UIView *customView;

@end


復(fù)制代碼代碼如下:

@implementation YYViewController

 


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.創(chuàng)建核心動(dòng)畫
    CAKeyframeAnimation *keyAnima=[CAKeyframeAnimation animation];
    //平移
    keyAnima.keyPath=@"position";
    //1.1告訴系統(tǒng)要執(zhí)行什么動(dòng)畫
    //創(chuàng)建一條路徑
    CGMutablePathRef path=CGPathCreateMutable();
    //設(shè)置一個(gè)圓的路徑
    CGPathAddEllipseInRect(path, NULL, CGRectMake(150, 100, 100, 100));
    keyAnima.path=path;
    
    //有create就一定要有release
    CGPathRelease(path);
    //1.2設(shè)置動(dòng)畫執(zhí)行完畢后,不刪除動(dòng)畫
    keyAnima.removedOnCompletion=NO;
    //1.3設(shè)置保存動(dòng)畫的最新狀態(tài)
    keyAnima.fillMode=kCAFillModeForwards;
    //1.4設(shè)置動(dòng)畫執(zhí)行的時(shí)間
    keyAnima.duration=5.0;
    //1.5設(shè)置動(dòng)畫的節(jié)奏
    keyAnima.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    
    //設(shè)置代理,開始—結(jié)束
    keyAnima.delegate=self;
    //2.添加核心動(dòng)畫
    [self.customView.layer addAnimation:keyAnima forKey:nil];
}

-(void)animationDidStart:(CAAnimation *)anim
{
    NSLog(@"開始動(dòng)畫");
}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    NSLog(@"結(jié)束動(dòng)畫");
}
@end


說明:可以通過path屬性,讓layer在指定的軌跡上運(yùn)動(dòng)。

 

停止動(dòng)畫:

復(fù)制代碼代碼如下:

#import "YYViewController.h"

 

@interface YYViewController ()
@property (weak, nonatomic) IBOutlet UIView *customView;
- (IBAction)stopOnClick:(UIButton *)sender;

@end


復(fù)制代碼代碼如下:

@implementation YYViewController

 


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.創(chuàng)建核心動(dòng)畫
    CAKeyframeAnimation *keyAnima=[CAKeyframeAnimation animation];
    //平移
    keyAnima.keyPath=@"position";
    //1.1告訴系統(tǒng)要執(zhí)行什么動(dòng)畫
    //創(chuàng)建一條路徑
    CGMutablePathRef path=CGPathCreateMutable();
    //設(shè)置一個(gè)圓的路徑
    CGPathAddEllipseInRect(path, NULL, CGRectMake(150, 100, 100, 100));
    keyAnima.path=path;
    
    //有create就一定要有release
    CGPathRelease(path);
    //1.2設(shè)置動(dòng)畫執(zhí)行完畢后,不刪除動(dòng)畫
    keyAnima.removedOnCompletion=NO;
    //1.3設(shè)置保存動(dòng)畫的最新狀態(tài)
    keyAnima.fillMode=kCAFillModeForwards;
    //1.4設(shè)置動(dòng)畫執(zhí)行的時(shí)間
    keyAnima.duration=5.0;
    //1.5設(shè)置動(dòng)畫的節(jié)奏
    keyAnima.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    
    //2.添加核心動(dòng)畫
    [self.customView.layer addAnimation:keyAnima forKey:@"wendingding"];
}

- (IBAction)stopOnClick:(UIButton *)sender {
    //停止self.customView.layer上名稱標(biāo)示為wendingding的動(dòng)畫
    [self.customView.layer removeAnimationForKey:@"wendingding"];
}
@end


 

實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

點(diǎn)擊停止動(dòng)畫,程序內(nèi)部會(huì)調(diào)用  [self.customView.layer removeAnimationForKey:@"wendingding"];停止self.customView.layer上名稱標(biāo)示為wendingding的動(dòng)畫。

3.圖標(biāo)抖動(dòng)

代碼示例:

復(fù)制代碼代碼如下:

//
//  YYViewController.m
//  12-圖標(biāo)抖動(dòng)
//
//  Created by apple on 14-6-21.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

 

#import "YYViewController.h"
#define angle2Radian(angle)  ((angle)/180.0*M_PI)

@interface YYViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;

@end


復(fù)制代碼代碼如下:

@implementation YYViewController

 

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //1.創(chuàng)建核心動(dòng)畫
    CAKeyframeAnimation *keyAnima=[CAKeyframeAnimation animation];
    keyAnima.keyPath=@"transform.rotation";
    //設(shè)置動(dòng)畫時(shí)間
    keyAnima.duration=0.1;
    //設(shè)置圖標(biāo)抖動(dòng)弧度
    //把度數(shù)轉(zhuǎn)換為弧度  度數(shù)/180*M_PI
    keyAnima.values=@[@(-angle2Radian(4)),@(angle2Radian(4)),@(-angle2Radian(4))];
    //設(shè)置動(dòng)畫的重復(fù)次數(shù)(設(shè)置為最大值)
    keyAnima.repeatCount=MAXFLOAT;
    
    keyAnima.fillMode=kCAFillModeForwards;
    keyAnima.removedOnCompletion=NO;
    //2.添加動(dòng)畫
    [self.iconView.layer addAnimation:keyAnima forKey:nil];
}

@end


說明:圖標(biāo)向左向右偏轉(zhuǎn)一個(gè)弧度(4),產(chǎn)生抖動(dòng)的視覺效果。

 

程序界面:
實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建



注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到IOS開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 清水河县| 临澧县| 阜宁县| 聂拉木县| 商都县| SHOW| 宜章县| 沙河市| 崇阳县| 平顺县| 丹江口市| 济南市| 丰顺县| 故城县| 同德县| 大丰市| 潞城市| 阳原县| 萨迦县| 铁力市| 潞西市| 安岳县| 鹿泉市| 耿马| 师宗县| 内黄县| 江安县| 绍兴县| 南涧| 正阳县| 龙里县| 灌云县| 文安县| 华阴市| 离岛区| 镇沅| 新蔡县| 白山市| 商都县| 荃湾区| 祁连县|