iOS開發-svga的使用
- 前言
- 開發準備
- 代碼
- 最后
前言
- iOS開發中的跨端影片有Lottie還有在視頻直播社交軟體上比較流行的是svga,
開發準備
- podfile匯入
pod 'SVGAPlayer'
代碼
- ViewController.m
#import "ViewController.h"
#import <SVGAPlayer/SVGA.h>
@interface ViewController ()
@property(nonatomic, strong) SVGAPlayer *svGAPlayer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.svGAPlayer];
}
- (SVGAPlayer *)svGAPlayer {
if(_svGAPlayer == nil) {
_svGAPlayer = [[SVGAPlayer alloc]init];
_svGAPlayer.contentMode = UIViewContentModeScaleAspectFill;
SVGAParser *parser = [[SVGAParser alloc] init];
__weak typeof(self) weakSelf = self;
[parser parseWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"123.svga" ofType:nil]] completionBlock:^(SVGAVideoEntity *videoItem) {
if (videoItem) {
weakSelf.svGAPlayer.videoItem = videoItem;
[weakSelf.svGAPlayer startAnimation];
}
} failureBlock:nil];
_svGAPlayer.userInteractionEnabled = YES;
_svGAPlayer.loops = INT16_MAX;
_svGAPlayer.clearsAfterStop = YES;
}
return _svGAPlayer;
}
@end
最后
- 官網鏈接
- svga影片下載
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/252159.html
標籤:其他
