Commit fe6b52577756a628a949f974b5d0cee170c91df1

Authored by 张旭
1 parent 55793dd9

封装飘心动画管理类

Showing 42 changed files with 557 additions and 1 deletions
LiveVideoCloud/LiveVideoCloud.xcodeproj/project.pbxproj
... ... @@ -106,6 +106,8 @@
106 106 D2029D091E6EAE2E0027CD92 /* Foundation+Log.m in Sources */ = {isa = PBXBuildFile; fileRef = D2029CF21E6EAE2E0027CD92 /* Foundation+Log.m */; };
107 107 D2029D0A1E6EAE2E0027CD92 /* ZXServerUrl.m in Sources */ = {isa = PBXBuildFile; fileRef = D2029CFE1E6EAE2E0027CD92 /* ZXServerUrl.m */; };
108 108 D2029D161E6EB00D0027CD92 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D2029D151E6EB00D0027CD92 /* AppDelegate.m */; };
  109 + D2575C461E76857100E3A8FC /* LVCAnimationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D2575C451E76857100E3A8FC /* LVCAnimationManager.m */; };
  110 + D2575C4A1E7685DE00E3A8FC /* UIView+Bubbling.m in Sources */ = {isa = PBXBuildFile; fileRef = D2575C481E7685DE00E3A8FC /* UIView+Bubbling.m */; };
109 111 D2888D941E6EB8B4003A77C8 /* LVCTabBar.m in Sources */ = {isa = PBXBuildFile; fileRef = D2888D931E6EB8B4003A77C8 /* LVCTabBar.m */; };
110 112 D2888D9E1E6EBF1B003A77C8 /* LVCLiveViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2888D9B1E6EBF1B003A77C8 /* LVCLiveViewController.m */; };
111 113 D2888DB11E6EC05F003A77C8 /* TempViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2888DB01E6EC05F003A77C8 /* TempViewController.m */; };
... ... @@ -343,6 +345,10 @@
343 345 D2029CFF1E6EAE2E0027CD92 /* UtilKits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UtilKits.h; sourceTree = "<group>"; };
344 346 D2029D121E6EAF8D0027CD92 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
345 347 D2029D151E6EB00D0027CD92 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
  348 + D2575C441E76857100E3A8FC /* LVCAnimationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCAnimationManager.h; sourceTree = "<group>"; };
  349 + D2575C451E76857100E3A8FC /* LVCAnimationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCAnimationManager.m; sourceTree = "<group>"; };
  350 + D2575C481E7685DE00E3A8FC /* UIView+Bubbling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Bubbling.m"; sourceTree = "<group>"; };
  351 + D2575C491E7685DE00E3A8FC /* UIView+Bubbling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Bubbling.h"; sourceTree = "<group>"; };
346 352 D2888D921E6EB8B4003A77C8 /* LVCTabBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCTabBar.h; sourceTree = "<group>"; };
347 353 D2888D931E6EB8B4003A77C8 /* LVCTabBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCTabBar.m; sourceTree = "<group>"; };
348 354 D2888D9A1E6EBF1B003A77C8 /* LVCLiveViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCLiveViewController.h; sourceTree = "<group>"; };
... ... @@ -784,6 +790,7 @@
784 790 D2888DA71E6EC014003A77C8 /* homeSections */,
785 791 D2888D951E6EBAA7003A77C8 /* LiveSections */,
786 792 D2888DAB1E6EC014003A77C8 /* mySections */,
  793 + D2575C431E76846900E3A8FC /* InteractionSections */,
787 794 D2029C751E6EADE10027CD92 /* ZXSections(例子) */,
788 795 );
789 796 path = Sections;
... ... @@ -990,6 +997,25 @@
990 997 path = AppDelegate;
991 998 sourceTree = "<group>";
992 999 };
  1000 + D2575C431E76846900E3A8FC /* InteractionSections */ = {
  1001 + isa = PBXGroup;
  1002 + children = (
  1003 + D2575C471E7685C500E3A8FC /* heartAnimation */,
  1004 + D2575C441E76857100E3A8FC /* LVCAnimationManager.h */,
  1005 + D2575C451E76857100E3A8FC /* LVCAnimationManager.m */,
  1006 + );
  1007 + path = InteractionSections;
  1008 + sourceTree = "<group>";
  1009 + };
  1010 + D2575C471E7685C500E3A8FC /* heartAnimation */ = {
  1011 + isa = PBXGroup;
  1012 + children = (
  1013 + D2575C491E7685DE00E3A8FC /* UIView+Bubbling.h */,
  1014 + D2575C481E7685DE00E3A8FC /* UIView+Bubbling.m */,
  1015 + );
  1016 + path = heartAnimation;
  1017 + sourceTree = "<group>";
  1018 + };
993 1019 D2888D911E6EB897003A77C8 /* View */ = {
994 1020 isa = PBXGroup;
995 1021 children = (
... ... @@ -1277,6 +1303,7 @@
1277 1303 D2029CA21E6EADE10027CD92 /* MJRefreshAutoFooter.m in Sources */,
1278 1304 D2029CC71E6EADE10027CD92 /* SVIndefiniteAnimatedView.m in Sources */,
1279 1305 D2029CA31E6EADE10027CD92 /* MJRefreshBackFooter.m in Sources */,
  1306 + D2575C4A1E7685DE00E3A8FC /* UIView+Bubbling.m in Sources */,
1280 1307 D2029CA61E6EADE10027CD92 /* MJRefreshHeader.m in Sources */,
1281 1308 D2029CC41E6EADE10027CD92 /* UIImageView+WebCache.m in Sources */,
1282 1309 D2029CC81E6EADE10027CD92 /* SVProgressAnimatedView.m in Sources */,
... ... @@ -1292,6 +1319,7 @@
1292 1319 D2029C921E6EADE10027CD92 /* UIImageView+AFNetworking.m in Sources */,
1293 1320 D2029C9E1E6EADE10027CD92 /* NSObject+MJCoding.m in Sources */,
1294 1321 D2029C991E6EADE10027CD92 /* MJFoundation.m in Sources */,
  1322 + D2575C461E76857100E3A8FC /* LVCAnimationManager.m in Sources */,
1295 1323 D2029C8A1E6EADE10027CD92 /* AFURLRequestSerialization.m in Sources */,
1296 1324 D2029D041E6EAE2E0027CD92 /* UILabel+ContentSize.m in Sources */,
1297 1325 D2029C871E6EADE10027CD92 /* AFHTTPSessionManager.m in Sources */,
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/Contents.json 0 → 100644
  1 +{
  2 + "info" : {
  3 + "version" : 1,
  4 + "author" : "xcode"
  5 + }
  6 +}
0 7 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_bluepig.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "ic_menu_bluepig.png",
  6 + "scale" : "1x"
  7 + }
  8 + ],
  9 + "info" : {
  10 + "version" : 1,
  11 + "author" : "xcode"
  12 + }
  13 +}
0 14 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_bluepig.imageset/ic_menu_bluepig.png 0 → 100644

26.1 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_bluepig2.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "ic_menu_bluepig2.png",
  6 + "scale" : "1x"
  7 + }
  8 + ],
  9 + "info" : {
  10 + "version" : 1,
  11 + "author" : "xcode"
  12 + }
  13 +}
0 14 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_bluepig2.imageset/ic_menu_bluepig2.png 0 → 100644

24.2 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_greenpig.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "ic_menu_greenpig.png",
  6 + "scale" : "1x"
  7 + }
  8 + ],
  9 + "info" : {
  10 + "version" : 1,
  11 + "author" : "xcode"
  12 + }
  13 +}
0 14 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_greenpig.imageset/ic_menu_greenpig.png 0 → 100644

26.9 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_greenpig2.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "ic_menu_greenpig2.png",
  6 + "scale" : "1x"
  7 + }
  8 + ],
  9 + "info" : {
  10 + "version" : 1,
  11 + "author" : "xcode"
  12 + }
  13 +}
0 14 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_greenpig2.imageset/ic_menu_greenpig2.png 0 → 100644

24.5 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_pinkpig.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "ic_menu_pinkpig.png",
  6 + "scale" : "1x"
  7 + }
  8 + ],
  9 + "info" : {
  10 + "version" : 1,
  11 + "author" : "xcode"
  12 + }
  13 +}
0 14 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_pinkpig.imageset/ic_menu_pinkpig.png 0 → 100644

24.3 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_pinkpig2.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "ic_menu_pinkpig2.png",
  6 + "scale" : "1x"
  7 + }
  8 + ],
  9 + "info" : {
  10 + "version" : 1,
  11 + "author" : "xcode"
  12 + }
  13 +}
0 14 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_pinkpig2.imageset/ic_menu_pinkpig2.png 0 → 100644

26.1 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_purplepig.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "ic_menu_purplepig.png",
  6 + "scale" : "1x"
  7 + }
  8 + ],
  9 + "info" : {
  10 + "version" : 1,
  11 + "author" : "xcode"
  12 + }
  13 +}
0 14 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_purplepig.imageset/ic_menu_purplepig.png 0 → 100644

26.3 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_purplepig2.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "ic_menu_purplepig2.png",
  6 + "scale" : "1x"
  7 + }
  8 + ],
  9 + "info" : {
  10 + "version" : 1,
  11 + "author" : "xcode"
  12 + }
  13 +}
0 14 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_purplepig2.imageset/ic_menu_purplepig2.png 0 → 100644

24.4 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_yellowpig.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "ic_menu_yellowpig.png",
  6 + "scale" : "1x"
  7 + }
  8 + ],
  9 + "info" : {
  10 + "version" : 1,
  11 + "author" : "xcode"
  12 + }
  13 +}
0 14 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_yellowpig.imageset/ic_menu_yellowpig.png 0 → 100644

26.2 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_yellowpig2.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "ic_menu_yellowpig2.png",
  6 + "scale" : "1x"
  7 + }
  8 + ],
  9 + "info" : {
  10 + "version" : 1,
  11 + "author" : "xcode"
  12 + }
  13 +}
0 14 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/ic_menu_yellowpig2.imageset/ic_menu_yellowpig2.png 0 → 100644

24.4 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/love.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "filename" : "love@2x.png",
  6 + "scale" : "2x"
  7 + },
  8 + {
  9 + "idiom" : "universal",
  10 + "filename" : "love@3x.png",
  11 + "scale" : "3x"
  12 + }
  13 + ],
  14 + "info" : {
  15 + "version" : 1,
  16 + "author" : "xcode"
  17 + }
  18 +}
0 19 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/love.imageset/love@2x.png 0 → 100644

1.9 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Interaction/love.imageset/love@3x.png 0 → 100644

2.99 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Begin to live.imageset/Begin to live.png renamed to LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/Begin to live.imageset/Begin to live.png

11.6 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/Begin to live.imageset/Contents.json renamed to LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/Begin to live.imageset/Contents.json
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/Contents.json 0 → 100644
  1 +{
  2 + "info" : {
  3 + "version" : 1,
  4 + "author" : "xcode"
  5 + }
  6 +}
0 7 \ No newline at end of file
... ...
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/home page-click on.imageset/Contents.json renamed to LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/home page-click on.imageset/Contents.json
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/home page-click on.imageset/home page-click on.png renamed to LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/home page-click on.imageset/home page-click on.png

2.93 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/home page.imageset/Contents.json renamed to LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/home page.imageset/Contents.json
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/home page.imageset/home page.png renamed to LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/home page.imageset/home page.png

2.68 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/my-click on.imageset/Contents.json renamed to LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/my-click on.imageset/Contents.json
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/my-click on.imageset/my-click on.png renamed to LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/my-click on.imageset/my-click on.png

3.01 KB

LiveVideoCloud/LiveVideoCloud/Assets.xcassets/my.imageset/Contents.json renamed to LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/my.imageset/Contents.json
LiveVideoCloud/LiveVideoCloud/Assets.xcassets/my.imageset/my.png renamed to LiveVideoCloud/LiveVideoCloud/Assets.xcassets/tabBar/my.imageset/my.png

2.89 KB

LiveVideoCloud/LiveVideoCloud/Classes/Sections/InteractionSections/LVCAnimationManager.h 0 → 100644
  1 +//
  2 +// LVCAnimationManager.h
  3 +// LiveVideoCloud
  4 +//
  5 +// Created by 张旭 on 2017/3/13.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +#import <UIKit/UIKit.h>
  11 +@interface LVCAnimationManager : NSObject
  12 +
  13 ++ (__nonnull instancetype)shareManager;
  14 +
  15 +//- (void)bubblingWithImage:(NSString *_Nonnull)image centerPoint:(CGPoint)centerPoint toView:(UIView *_Nonnull)toView;
  16 +//
  17 +//- (void)bubblingWithImages:(NSArray< NSString *> *_Nonnull)images centerPoint:(CGPoint)centerPoint toView:(UIView *_Nonnull)toView;
  18 +
  19 +/**
  20 + 单次出现飘心效果
  21 +
  22 + @param centerPoint 心中心点
  23 + @param toView 目标视图
  24 + */
  25 +- (void)bubblingWithCenterPoint:(CGPoint)centerPoint toView:(UIView *_Nonnull)toView;
  26 +
  27 +/**
  28 + 重复出现飘心效果
  29 +
  30 + @param centerPoint 心中心点
  31 + @param toView 目标视图
  32 + @param speed 每s执行的次数
  33 + */
  34 +- (void)bubblingWithCenterPoint:(CGPoint)centerPoint toView:(UIView *_Nonnull)toView speed:(CGFloat)speed;
  35 +@end
... ...
LiveVideoCloud/LiveVideoCloud/Classes/Sections/InteractionSections/LVCAnimationManager.m 0 → 100644
  1 +//
  2 +// LVCAnimationManager.m
  3 +// LiveVideoCloud
  4 +//
  5 +// Created by 张旭 on 2017/3/13.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "LVCAnimationManager.h"
  10 +#import "UIView+Bubbling.h"
  11 +
  12 +@interface LVCAnimationManager ()
  13 +
  14 +@property (nonatomic ,strong) NSArray * _Nullable images;
  15 +@property (nonatomic ,strong) CADisplayLink * _Nullable link;
  16 +@property (nonatomic ,strong) UIView * _Nullable toView;
  17 +@property (nonatomic ,assign) CGPoint centerPoint;
  18 +
  19 +@end
  20 +
  21 +@implementation LVCAnimationManager
  22 +
  23 +static NSString * loveImageName = @"love";
  24 +
  25 +#pragma mark - SINGLETON 单例
  26 +static LVCAnimationManager * __singleton__;
  27 +
  28 ++ (__nonnull instancetype)shareManager
  29 +{
  30 + static dispatch_once_t once_t;
  31 + dispatch_once(&once_t, ^{
  32 + __singleton__ = [[[self class] alloc] init];
  33 + __singleton__.images = @[@"ic_menu_bluepig",
  34 + @"ic_menu_bluepig2",
  35 + @"ic_menu_greenpig",
  36 + @"ic_menu_greenpig2",
  37 + @"ic_menu_pinkpig",
  38 + @"ic_menu_pinkpig2",
  39 + @"ic_menu_purplepig",
  40 + @"ic_menu_purplepig2",
  41 + @"ic_menu_yellowpig",
  42 + @"ic_menu_yellowpig2"];
  43 + });
  44 + return __singleton__;
  45 +}
  46 +
  47 +/**
  48 + 单次出现飘心效果
  49 +
  50 + @param centerPoint 心中心点
  51 + @param toView 目标视图
  52 + */
  53 +- (void)bubblingWithCenterPoint:(CGPoint)centerPoint toView:(UIView *_Nonnull)toView
  54 +{
  55 + [toView bubblingWithImage:[UIImage imageNamed:loveImageName] center:centerPoint];
  56 + [toView bubblingWithImages:__singleton__.images center:centerPoint];
  57 +}
  58 +
  59 +/**
  60 + 重复出现飘心效果
  61 +
  62 + @param centerPoint 心中心点
  63 + @param toView 目标视图
  64 + @param speed 每s执行的次数
  65 + */
  66 +- (void)bubblingWithCenterPoint:(CGPoint)centerPoint toView:(UIView *_Nonnull)toView speed:(CGFloat)speed
  67 +{
  68 + CGFloat defSpeed = 2;
  69 + if (speed != 0) {
  70 + defSpeed = speed;
  71 + }
  72 + self.toView = toView;
  73 + self.centerPoint = centerPoint;
  74 + self.link = [CADisplayLink displayLinkWithTarget:self selector:@selector(repeatAni)];
  75 + [self.link setPreferredFramesPerSecond:defSpeed];
  76 + [self.link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
  77 +}
  78 +
  79 +- (void)repeatAni
  80 +{
  81 + [self.toView bubblingWithImage:[UIImage imageNamed:loveImageName] center:self.centerPoint];
  82 + [self.toView bubblingWithImages:__singleton__.images center:self.centerPoint];
  83 +}
  84 +@end
... ...
LiveVideoCloud/LiveVideoCloud/Classes/Sections/InteractionSections/heartAnimation/UIView+Bubbling.h 0 → 100644
  1 +//
  2 +// UIView+Bubbling.h
  3 +// ThumbUpDemo
  4 +//
  5 +// Created by 张旭 on 2017/3/10.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +@interface UIView (Bubbling)<CAAnimationDelegate>
  12 +
  13 +- (void)bubblingWithImage:(UIImage *_Nonnull)image center:(CGPoint)center;
  14 +
  15 +- (void)bubblingWithImages:(NSArray <NSString *>*_Nonnull)images center:(CGPoint)center;
  16 +@end
... ...
LiveVideoCloud/LiveVideoCloud/Classes/Sections/InteractionSections/heartAnimation/UIView+Bubbling.m 0 → 100644
  1 +//
  2 +// UIView+Bubbling.m
  3 +// ThumbUpDemo
  4 +//
  5 +// Created by 张旭 on 2017/3/10.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "UIView+Bubbling.h"
  10 +
  11 +#define LAYER_ANIMATION_NAME @"layerName"
  12 +
  13 +// 十六进制颜色值 使用:HEX_COLOR(0xf8f8f8)
  14 +#define HEX_COLOR_ALPHA(_HEX_,a) [UIColor colorWithRed:((float)((_HEX_ & 0xFF0000) >> 16))/255.0 green:((float)((_HEX_ & 0xFF00) >> 8))/255.0 blue:((float)(_HEX_ & 0xFF))/255.0 alpha:a]
  15 +
  16 +#define HEX_COLOR(_HEX_) HEX_COLOR_ALPHA(_HEX_, 1.0)
  17 +
  18 +#define heartWidth 28.0f
  19 +static CGPoint aimCenter;
  20 +static CGFloat aimHeight = 0.f;
  21 +
  22 +@implementation UIView (Bubbling)
  23 +
  24 +- (void)bubblingWithImage:(UIImage *_Nonnull)image center:(CGPoint)center{
  25 + UIColor *randomColor = [self randomColor];
  26 + [self exportImage:image withColor:randomColor center:center];
  27 +}
  28 +
  29 +- (void)bubblingWithImages:(NSArray <NSString *>*_Nonnull)images center:(CGPoint)center{
  30 + if (!images)return;
  31 + long index = rand() % images.count;
  32 + UIImage *image = [UIImage imageNamed:images[index]];
  33 + [self exportImage:image withColor:nil center:center];
  34 +}
  35 +
  36 +//static CGFloat PI = M_PI;
  37 +//-(void)animateInView:(UIView *)view{
  38 +// NSTimeInterval totalAnimationDuration = 6;
  39 +// CGFloat heartSize = CGRectGetWidth(self.bounds);
  40 +// CGFloat heartCenterX = self.center.x;
  41 +// CGFloat viewHeight = CGRectGetHeight(view.bounds);
  42 +//
  43 +// //Pre-Animation setup
  44 +// self.transform = CGAffineTransformMakeScale(0, 0);
  45 +// self.alpha = 0;
  46 +//
  47 +// //Bloom
  48 +// [UIView animateWithDuration:1 delay:0.0 usingSpringWithDamping:0.6 initialSpringVelocity:0.8 options:UIViewAnimationOptionCurveEaseOut animations:^{
  49 +// self.transform = CGAffineTransformIdentity;
  50 +// self.alpha = 0.9;
  51 +// } completion:NULL];
  52 +// //随机值0、1
  53 +// NSInteger i = arc4random_uniform(2);
  54 +// NSInteger rotationDirection = 1- (2*i);// -1 OR 1
  55 +// //随机值0~9
  56 +// NSInteger rotationFraction = arc4random_uniform(10);
  57 +//
  58 +// [UIView animateWithDuration:totalAnimationDuration animations:^{
  59 +// self.transform = CGAffineTransformMakeRotation(rotationDirection * PI/(16 + rotationFraction*0.2));
  60 +// } completion:NULL];
  61 +//
  62 +// UIBezierPath *heartTravelPath = [UIBezierPath bezierPath];
  63 +// [heartTravelPath moveToPoint:self.center];
  64 +//
  65 +// //random end point
  66 +// CGPoint endPoint = CGPointMake(heartCenterX + (rotationDirection) * arc4random_uniform(2*heartSize), viewHeight/6.0 + arc4random_uniform(viewHeight/4.0));
  67 +//
  68 +// //random Control Points
  69 +// NSInteger j = arc4random_uniform(2);
  70 +// NSInteger travelDirection = 1- (2*j);// -1 OR 1
  71 +//
  72 +// //randomize x and y for control points
  73 +// CGFloat xDelta = (heartSize/2.0 + arc4random_uniform(2*heartSize)) * travelDirection;
  74 +// CGFloat yDelta = MAX(endPoint.y ,MAX(arc4random_uniform(8*heartSize), heartSize));
  75 +// CGPoint controlPoint1 = CGPointMake(heartCenterX + xDelta, viewHeight - yDelta);
  76 +// CGPoint controlPoint2 = CGPointMake(heartCenterX - 2*xDelta, yDelta);
  77 +//
  78 +// [heartTravelPath addCurveToPoint:endPoint controlPoint1:controlPoint1 controlPoint2:controlPoint2];
  79 +//
  80 +// CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  81 +// keyFrameAnimation.path = heartTravelPath.CGPath;
  82 +// keyFrameAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
  83 +// keyFrameAnimation.duration = totalAnimationDuration + endPoint.y/viewHeight;
  84 +// [self.layer addAnimation:keyFrameAnimation forKey:@"positionOnPath"];
  85 +//
  86 +// //Alpha & remove from superview
  87 +// [UIView animateWithDuration:totalAnimationDuration animations:^{
  88 +// self.alpha = 0.0;
  89 +// } completion:^(BOOL finished) {
  90 +// [self removeFromSuperview];
  91 +// }];
  92 +//
  93 +//}
  94 +
  95 +- (void)startAnimationHeartLayer:(CALayer *)heartLayer
  96 +{
  97 + CGFloat duration = 2.f + arc4random_uniform(10) * 0.1;
  98 +
  99 + //位置动画
  100 + CABasicAnimation *posAnimation =
  101 + [CABasicAnimation animationWithKeyPath:@"position"];
  102 + // -30 30
  103 + CGFloat destination_x = heartLayer.position.x + arc4random_uniform(60) - 30 ;
  104 +
  105 + CGFloat destinaion_y =
  106 + heartLayer.position.y / 2;
  107 + CGPoint destination = CGPointMake(destination_x, destinaion_y);
  108 + [posAnimation setToValue:[NSValue valueWithCGPoint:destination]];
  109 + [posAnimation setTimingFunction:
  110 + [CAMediaTimingFunction functionWithControlPoints:0.6f :0.7f :0.6 :0.7]];
  111 +
  112 +// NSInteger i = arc4random_uniform(2);
  113 +// NSInteger rotationDirection = 1- (2*i);// -1 OR 1
  114 +//
  115 +// UIBezierPath *heartTravelPath = [UIBezierPath bezierPath];
  116 +// [heartTravelPath moveToPoint:aimCenter];
  117 +//
  118 +// //random end point
  119 +// CGPoint endPoint = CGPointMake(aimCenter.x + (rotationDirection) * arc4random_uniform(2*heartWidth), aimCenter.y/2 + arc4random_uniform(aimHeight/4.0));
  120 +//
  121 +// //random Control Points
  122 +// NSInteger j = arc4random_uniform(2);
  123 +// NSInteger travelDirection = 1- (2*j);// -1 OR 1
  124 +//
  125 +// //randomize x and y for control points
  126 +// CGFloat xDelta = (heartWidth/2.0 + arc4random_uniform(2*heartWidth)) * travelDirection;
  127 +// CGFloat yDelta = MAX(endPoint.y ,MAX(arc4random_uniform(8*heartWidth), heartWidth));
  128 +// CGPoint controlPoint1 = CGPointMake(aimCenter.x + xDelta, aimHeight - yDelta);
  129 +// CGPoint controlPoint2 = CGPointMake(aimCenter.x - 2*xDelta, yDelta);
  130 +//
  131 +// [heartTravelPath addCurveToPoint:endPoint controlPoint1:controlPoint1 controlPoint2:controlPoint2];
  132 +//
  133 +// CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  134 +// keyFrameAnimation.path = heartTravelPath.CGPath;
  135 +// keyFrameAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
  136 +// keyFrameAnimation.duration = duration + endPoint.y/aimHeight;
  137 +// [heartLayer addAnimation:keyFrameAnimation forKey:@"positionOnPath"];
  138 +
  139 + //透明度动画
  140 + CAKeyframeAnimation *alphaAnimation =
  141 + [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
  142 + alphaAnimation.values = @[@1.0,@1.0,@0.0];
  143 + alphaAnimation.keyTimes = @[@0.0,@0.90,@1.0];
  144 +
  145 + //旋转动画
  146 + CABasicAnimation *angleAnimation =
  147 + [CABasicAnimation animationWithKeyPath:@"transform"];
  148 + [angleAnimation setFromValue:
  149 + [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0f, 1.0f, 1.0f)]];
  150 + CATransform3D destTrans =
  151 + CATransform3DMakeRotation(M_PI/4, 0, 0, (arc4random() % 2000) /1000.0f -1);
  152 + destTrans = CATransform3DScale(destTrans, 1.5f, 1.5f, 1.5f);
  153 + [angleAnimation setToValue:[NSValue valueWithCATransform3D:destTrans]];
  154 + angleAnimation.beginTime = 0.2;
  155 +
  156 + //缩放
  157 + CABasicAnimation *scaleAnimation =
  158 + [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  159 + [scaleAnimation setFromValue:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1f, 0.1f, 1.0f)]];
  160 + CATransform3D scaleTrans = CATransform3DMakeScale(1.0f, 1.0f, 1.0f);
  161 + [scaleAnimation setToValue:[NSValue valueWithCATransform3D:scaleTrans]];
  162 + scaleAnimation.duration = 0.2;
  163 +
  164 + CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
  165 + [groupAnimation setAnimations:@[posAnimation,alphaAnimation,angleAnimation]];
  166 + [groupAnimation setDuration:duration];
  167 + [groupAnimation setRemovedOnCompletion:YES];
  168 +
  169 + groupAnimation.delegate = self;
  170 + [groupAnimation setValue:heartLayer
  171 + forKey:LAYER_ANIMATION_NAME];
  172 +
  173 + [heartLayer addAnimation:groupAnimation forKey:nil];
  174 +}
  175 +
  176 +-(void)exportImage:(UIImage *)image withColor:(UIColor *)color center:(CGPoint)center{
  177 + if (!image)return;
  178 + aimCenter = center;
  179 + CGFloat width = heartWidth;
  180 + CGFloat height = width * image.size.height / image.size.width;
  181 + aimHeight = height;
  182 + CGRect frame =
  183 + CGRectMake(center.x - width/2 - 15,
  184 + center.y-height/2 - 38,
  185 + width,
  186 + height);
  187 +
  188 + CALayer *heartLayer = [CALayer layer];
  189 + heartLayer.opacity = 0.0f;
  190 + heartLayer.frame = frame;
  191 +
  192 + if (color)
  193 + {
  194 + CALayer *maskLayer = [CALayer layer];
  195 + maskLayer.frame = CGRectMake(0, 0, width, height);
  196 + maskLayer.contents = (__bridge id)image.CGImage;
  197 + maskLayer.contentsGravity = kCAGravityResizeAspect;
  198 + heartLayer.opacity = 0.0f;
  199 + heartLayer.mask = maskLayer;
  200 + heartLayer.backgroundColor = color.CGColor;
  201 + }
  202 + else
  203 + {
  204 + heartLayer.contents = (__bridge id)image.CGImage;
  205 + }
  206 +
  207 + [self.layer insertSublayer:heartLayer
  208 + above:self.layer];
  209 +
  210 + //动画
  211 + [self startAnimationHeartLayer:heartLayer];
  212 +}
  213 +
  214 +- (UIColor *)randomColor{
  215 + NSArray *colors =
  216 + @[ HEX_COLOR(0xFC6782), HEX_COLOR(0xFFEE58), HEX_COLOR(0x94EFDF),
  217 + HEX_COLOR(0x50E3C2), HEX_COLOR(0xB2D7FF), HEX_COLOR(0xFDDA02),
  218 + HEX_COLOR(0xBAD311), HEX_COLOR(0x58E7F9), HEX_COLOR(0xFF5252),
  219 + HEX_COLOR(0xAE91FC), HEX_COLOR(0xBCF87F), HEX_COLOR(0x29B6F6),
  220 + HEX_COLOR(0xF5A623), HEX_COLOR(0xFB3CB2), HEX_COLOR(0xFFA68A)];
  221 +
  222 + int index = rand() % colors.count;
  223 + UIColor *color = colors[index];
  224 +
  225 + return color;
  226 +}
  227 +@end
... ...
LiveVideoCloud/LiveVideoCloud/UtilKits/Const/ZXConst.h
... ... @@ -22,3 +22,6 @@ UIKIT_EXTERN CGFloat const kTitleFont;
22 22  
23 23 /** 内容字体字号 */
24 24 UIKIT_EXTERN CGFloat const kContentFont;
  25 +
  26 +/** 详细内容字体字号 */
  27 +UIKIT_EXTERN CGFloat const kDetailContentFont;
... ...
LiveVideoCloud/LiveVideoCloud/UtilKits/Const/ZXConst.m
... ... @@ -19,4 +19,7 @@ CGFloat const kTimeoutInterval = 10.0;
19 19 CGFloat const kTitleFont = 16.0;
20 20  
21 21 /** 内容字体字号 */
22   -CGFloat const kContentFont;
  22 +CGFloat const kContentFont = 14.0;
  23 +
  24 +/** 详细内容字体字号 */
  25 +CGFloat const kDetailContentFont = 12.0;
... ...