iOS Lottie 动画应用

准备工作:

需要一个动画的json的文件,或者json字符串,一般由UI设计人员生成的,直接导入到project里面就可以;

1 在Podfile里面引入第三方库lottie-ios,

版本2.5.3是objective-c的版本

也可以引入最新的版本是swift的版本:pod 'lottie-ios', :git => 'https://github.com/airbnb/lottie-ios.git'

Podfile内容如下:

 

# platform :ios, '9.0'

 

target 'LottieTest' do

  use_frameworks!

  pod 'lottie-ios', '=2.5.3'

end

2 在mac的终端中 pod install

3 直接在代码中应用动画的方法

代码如下:

#import "ViewController.h"

#import "Lottie.h"

 

@interface ViewController ()

{

    LOTAnimationView *_loadingView;

}

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

}

 

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

    if (!_loadingView) {

         _loadingView = [LOTAnimationView animationNamed:@"xxxxxjsonfile"];

        _loadingView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width);

        _loadingView.center = self.view.center;

        _loadingView.loopAnimation = YES;

        _loadingView.contentMode = UIViewContentModeScaleAspectFill;

        _loadingView.animationSpeed = 0.5;

    }

    [self.view addSubview:_loadingView];

    [_loadingView play];

}

你可能感兴趣的:(ios,移动开发)