MOClickActiveGuideView.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // MOClickActiveGuideView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/4/23.
  6. //
  7. #import "MOClickActiveGuideView.h"
  8. @interface MOClickActiveGuideView ()<SVGAPlayerDelegate>
  9. @property (nonatomic, strong) MOSVGACustomPlayer *aPlayer; //引导动画
  10. @property (nonatomic, strong) SVGAParser *aParser;
  11. @property (nonatomic, assign) BOOL shouldPlayOnceMore;//需要多播放一次
  12. @end
  13. @implementation MOClickActiveGuideView
  14. + (instancetype)moClickActiveGuideView{
  15. return [[[NSBundle mainBundle] loadNibNamed:@"MOClickActiveGuideView" owner:self options:nil] firstObject];
  16. }
  17. - (void)awakeFromNib{
  18. [super awakeFromNib];
  19. [self addSubview:self.aPlayer];
  20. CGFloat width = SCREENWIDTH;
  21. CGFloat y = SCREENHEIGHT - 500;
  22. self.aPlayer.frame = CGRectMake(0, y, width, 500);
  23. WEAKSELF
  24. [self.aParser parseWithNamed:@"icon_guide_click_active" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  25. if (videoItem) {
  26. weakSelf.aPlayer.videoItem = videoItem;
  27. [weakSelf.aPlayer startAnimation];
  28. }
  29. } failureBlock:^(NSError * _Nonnull error) {
  30. MOLogV(@"播放失败~~~~~~~~");
  31. }];
  32. }
  33. - (IBAction)closeBtnClick:(id)sender {
  34. [self dismissClickActiveGuideView];
  35. }
  36. - (void)showClickActiveGuideView//界面显示动画
  37. {
  38. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  39. [keyWindow addSubview:self];
  40. self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
  41. }
  42. - (void)showClickActiveGuideViewInView:(UIView *)superView {
  43. [superView addSubview:self];
  44. self.frame = superView.bounds;
  45. }
  46. - (void)dismissClickActiveGuideView
  47. {
  48. [self removeFromSuperview];
  49. }
  50. //延迟一次播放后消失
  51. - (void)delayToDismiss
  52. {
  53. // [self performSelector:@selector(dismissClickActiveGuideView) withObject:nil afterDelay:2.0];
  54. self.shouldPlayOnceMore = YES;
  55. }
  56. /// 动画播放完成(一次循环结束)
  57. - (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player {
  58. [self dismissClickActiveGuideView];
  59. }
  60. - (void)svgaPlayer:(SVGAPlayer *)player didAnimatedToPercentage:(CGFloat)percentage {
  61. if (self.shouldPlayOnceMore) {
  62. if (percentage == 1.0) {
  63. self.aPlayer.loops = 1;
  64. [self.aPlayer startAnimation];
  65. }
  66. }
  67. }
  68. #pragma mark - setter/getter
  69. - (MOSVGACustomPlayer *)aPlayer {
  70. if (_aPlayer == nil) {
  71. _aPlayer = [[MOSVGACustomPlayer alloc] init];
  72. _aPlayer.delegate = self;
  73. _aPlayer.loops = 0;
  74. _aPlayer.clearsAfterStop = YES;
  75. _aPlayer.contentMode = UIViewContentModeScaleAspectFit;
  76. }
  77. return _aPlayer;
  78. }
  79. - (SVGAParser *)aParser{
  80. if (_aParser == nil) {
  81. _aParser = [[SVGAParser alloc]init];
  82. }
  83. return _aParser;
  84. }
  85. @end