CarAnimationPlayer.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // CarAnimationPlayer.m
  3. // FanweApp
  4. //
  5. // Created by 志刚杨 on 2017/12/20.
  6. // Copyright © 2017年 voidcat. All rights reserved.
  7. //
  8. #import "CarAnimationPlayer.h"
  9. @interface CarAnimationPlayer()<SVGAPlayerDelegate>
  10. @end
  11. static SVGAParser *parser;
  12. @implementation CarAnimationPlayer
  13. {
  14. NSURL *svgUrl;
  15. UIImageView *rankImgView;
  16. UILabel *userNameLabel;
  17. UILabel *contentlab;
  18. }
  19. - (instancetype)initWithFrame:(CGRect)frame
  20. {
  21. self = [super initWithFrame:frame];
  22. if (self) {
  23. [self addSubview:self.aPlayer];
  24. self.aPlayer.delegate = self;
  25. self.aPlayer.frame = self.bounds;
  26. self.aPlayer.height -= 80;
  27. self.aPlayer.y += 80;
  28. self.aPlayer.loops = 1;
  29. self.aPlayer.contentMode = UIViewContentModeScaleAspectFit;
  30. self.aPlayer.clearsAfterStop = YES;
  31. // self.aPlayer.backgroundColor = kRedColor;
  32. parser = [[SVGAParser alloc] init];
  33. _titleView = [[UIImageView alloc]init];
  34. _titleView.left = kScreenW + kRealValue(120);
  35. _titleView.top = kStatusBarHeight + 180;
  36. UIImage *image = [UIImage imageNamed:@"car_img_tip_bg"];
  37. // image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 25, 0, 25) resizingMode:UIImageResizingModeStretch];
  38. [_titleView setImage:image];
  39. _titleView.size = image.size;
  40. // _titleView.contentMode = UIViewContentModeScal;
  41. [self addSubview:_titleView];
  42. rankImgView = [[UIImageView alloc] init];
  43. rankImgView.layer.cornerRadius = 24;
  44. rankImgView.clipsToBounds = YES;
  45. contentlab = [[UILabel alloc] init];
  46. userNameLabel = [[UILabel alloc] init];
  47. userNameLabel.textColor = RGB(246, 219, 154);
  48. userNameLabel.font = [UIFont systemFontOfSize:13];
  49. contentlab.font = [UIFont systemFontOfSize:13];
  50. contentlab.textColor = kWhiteColor;
  51. // contentlab.textColor = KHighlight;
  52. [_titleView addSubview:rankImgView];
  53. [_titleView addSubview:userNameLabel];
  54. [_titleView addSubview:contentlab];
  55. [self setUpLayout];
  56. }
  57. return self;
  58. }
  59. -(void)setUpLayout
  60. {
  61. [rankImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.centerY.equalTo(_titleView);
  63. make.left.equalTo(_titleView).offset(2);
  64. make.width.equalTo(@48);
  65. make.height.equalTo(@48);
  66. }];
  67. [userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.equalTo(_titleView).offset(5);
  69. make.left.equalTo(rankImgView.mas_right).offset(5);
  70. make.height.equalTo(@13);
  71. }];
  72. // rankImgView.frame = CGRectMake(0, 120+kStatusBarHeight, 28, 13);
  73. // userNameLabel.frame = CGRectMake(rankImgView.right + 5, 120+kStatusBarHeight, [userNameLabel.text textSizeIn:CGSizeMake(MAXFLOAT, MAXFLOAT) font:[UIFont systemFontOfSize:15]].width, 15);
  74. // contentlab.frame = CGRectMake(userNameLabel.right + 5, 120+kStatusBarHeight, [contentlab.text textSizeIn:CGSizeMake(MAXFLOAT, MAXFLOAT) font:[UIFont systemFontOfSize:15]].width, 15);
  75. [contentlab mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.bottom.equalTo(_titleView).offset(-5);
  77. make.left.equalTo(rankImgView.mas_right).offset(5);
  78. make.height.equalTo(@13);
  79. }];
  80. }
  81. - (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player;
  82. {
  83. if([self.delegate respondsToSelector:@selector(CarAnimationHiddenPlayerDelegate)])
  84. {
  85. [self.delegate CarAnimationHiddenPlayerDelegate];
  86. }
  87. }
  88. -(void)setContent:(UserModel *)userModel
  89. {
  90. [rankImgView sd_setImageWithURL:[NSURL URLWithString:userModel.head_image] placeholderImage:kDefaultPreloadHeadImg];
  91. userNameLabel.text = userModel.nick_name;
  92. contentlab.text = [NSString stringWithFormat:ASLocalizedString(@"乘坐【%@】驾到"),userModel.noble_car_name];
  93. svgUrl = [NSURL URLWithString:userModel.noble_car_url];
  94. [parser parseWithURL:svgUrl completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  95. self.aPlayer.videoItem = videoItem;
  96. [self.aPlayer startAnimation];
  97. } failureBlock:^(NSError * _Nullable error) {
  98. [[BGHUDHelper sharedInstance] tipMessage:[NSString stringWithFormat:ASLocalizedString(@"座驾播放错误%@"),error]];
  99. }];
  100. [UIView animateWithDuration:1 animations:^{
  101. CGRect frame = _titleView.frame;
  102. frame.origin.x= ( kScreenW - _titleView.width )/ 2;
  103. _titleView.frame = frame;
  104. }];
  105. }
  106. - (SVGAPlayer *)aPlayer {
  107. if (_aPlayer == nil) {
  108. _aPlayer = [[SVGAPlayer alloc] init];
  109. }
  110. return _aPlayer;
  111. }
  112. @end