Prechádzať zdrojové kódy

名称闪光 暂时提交

SuperC 1 rok pred
rodič
commit
bb3d986d27

BIN
MiMoLive/MiMoLive.xcworkspace/xcuserdata/yanxuyao.xcuserdatad/UserInterfaceState.xcuserstate


BIN
MiMoLive/MiMoLive/3rdParty/.DS_Store


+ 2 - 0
MiMoLive/MiMoLive/3rdParty/FBShimmering/MOShimmerLabel.h

@@ -49,6 +49,8 @@ typedef NS_ENUM(NSInteger, ShimmerStyle) {
 /// 停止闪光动画
 - (void)stopShimmer;
 
+- (void)prepareForReuse;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 121 - 35
MiMoLive/MiMoLive/3rdParty/FBShimmering/MOShimmerLabel.m

@@ -111,6 +111,23 @@
     }
 }
 
+#pragma mark - Cell
+// 添加一个方法来处理 Cell 重用
+- (void)prepareForReuse {
+    [self stopShimmer];
+
+    // 重新创建必要的对象
+    self.shimmerLabel = [[UILabel alloc] initWithFrame:self.bounds];
+    [self addSubview:self.shimmerLabel];
+    self.shimmerLayer = [CAGradientLayer layer];
+    
+    // 恢复原始状态
+    [super setTextColor:self.originalTextColor];
+    [super setText:self.originalText];
+    [super setAttributedText:self.originalAttributedText];
+}
+
+
 #pragma mark - Override Properties
 
 /// 重写setText方法,确保动画状态正确
@@ -229,12 +246,21 @@
 - (void)stopShimmer {
     if (!self.shimmerIsPlaying) return;
     
-    [self.shimmerLayer removeAllAnimations];
-    [self.layer removeAllAnimations];
-    [self.shimmerLayer removeFromSuperlayer];
-    [self.shimmerLabel removeFromSuperview];
-    self.layer.mask = nil;
-    self.shimmerLabel.layer.mask = nil;
+    @try {
+        [self.shimmerLayer removeAllAnimations];
+        [self.layer removeAllAnimations];
+        self.layer.mask = nil;
+        if (self.shimmerLabel.layer) {
+            self.shimmerLabel.layer.mask = nil;
+        }
+        [self.shimmerLayer removeFromSuperlayer];
+//        [self.shimmerLabel removeFromSuperview];
+        self.shimmerLabel.hidden = YES;
+        
+    } @catch (NSException *exception) {
+        NSLog(@"MOShimmerLabel stopShimmer exception: %@", exception);
+    }
+    
     self.shimmerIsPlaying = NO;
 }
 
@@ -243,8 +269,34 @@
 /// 开始闪光动画
 /// @param force 是否强制重新开始动画
 - (void)startShimmerWithForce:(BOOL)force {
-    if (!force && self.shimmerIsPlaying) return;
-    self.shimmerIsPlaying = YES;
+    
+    
+    @try {
+        if (!force && self.shimmerIsPlaying) return;
+        if (!self.window || self.bounds.size.width <= 0) return; // 添加显示检查
+        
+        // 确保必要组件存在
+        if (!self.shimmerConfig) {
+            self.shimmerConfig = [[ShimmerLabelConfig alloc] init];
+        }
+        
+        // 确保基础组件存在
+        if (!self.shimmerLabel) {
+            self.shimmerLabel = [[UILabel alloc] initWithFrame:self.bounds];
+            [self addSubview:self.shimmerLabel];
+        }
+        
+        if (!self.shimmerLayer) {
+            self.shimmerLayer = [CAGradientLayer layer];
+        }
+        
+        self.shimmerIsPlaying = YES;
+        // ... 原有的动画设置代码 ...
+    } @catch (NSException *exception) {
+        NSLog(@"MOShimmerLabel startShimmerWithForce exception: %@", exception);
+    }
+    
+    self.shimmerLabel.hidden = NO;
     
     CAAnimation *animation;
     switch (self.shimmerConfig.shimmerStyle) {
@@ -664,15 +716,43 @@
     if (!newWindow) {
         [self stopShimmer];
     }
+    else {
+        // Cell 显示时,如果需要动画效果则重新开始
+        if (self.shimmerConfig.shimmerStyle != ShimmerStyleNone) {
+            [self startShimmerWithForce:YES];
+        }
+    }
 }
 
 - (void)didMoveToWindow {
     [super didMoveToWindow];
     
-    if (self.window &&
-        self.shimmerConfig.shimmerStyle != ShimmerStyleNone &&
-        !self.shimmerIsPlaying) {
-        [self startShimmerWithForce:NO];
+    @try {
+        // 添加安全检查
+        if (!self.shimmerConfig) {
+            self.shimmerConfig = [[ShimmerLabelConfig alloc] init];
+        }
+        
+        if (!self.shimmerLabel) {
+            self.shimmerLabel = [[UILabel alloc] initWithFrame:self.bounds];
+            [self addSubview:self.shimmerLabel];
+        }
+        
+        if (!self.shimmerLayer) {
+            self.shimmerLayer = [CAGradientLayer layer];
+        }
+        
+        // 确保在合适的时机开始动画
+        if (self.window &&
+            self.shimmerConfig.shimmerStyle != ShimmerStyleNone &&
+            !self.shimmerIsPlaying &&
+            self.bounds.size.width > 0) {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [self startShimmerWithForce:NO];
+            });
+        }
+    } @catch (NSException *exception) {
+        NSLog(@"MOShimmerLabel didMoveToWindow exception: %@", exception);
     }
 }
 
@@ -699,32 +779,38 @@
 - (void)layoutSubviews {
     [super layoutSubviews];
     
-    if (self.bounds.size.width <= 0) return;
-    
-    BOOL needForceShimmer = !CGSizeEqualToSize(self.bounds.size, self.shimmerLastSize);
-    self.shimmerLastSize = self.bounds.size;
-    
-    // 同步 shimmerLabel 的基本属性
-    self.shimmerLabel.frame = self.bounds;
-    self.shimmerLabel.font = self.font;
-    self.shimmerLabel.textAlignment = self.textAlignment;
-    self.shimmerLabel.numberOfLines = self.numberOfLines;
+    if (self.bounds.size.width <= 0 || !self.window) return;
     
-    if (self.shimmerConfig.shimmerStyle == ShimmerStyleColorsFlow) {
-        self.shimmerLayer.frame = CGRectMake(-self.shimmerConfig.shimmerWidth, 0,
-                                            [self rawWidth] + self.shimmerConfig.shimmerWidth * 2,
-                                            self.bounds.size.height);
-        self.shimmerLabel.frame = CGRectMake(self.shimmerConfig.shimmerWidth, 0,
-                                            [self rawMaskWidth],
-                                            self.bounds.size.height);
-    } else {
-        self.shimmerLayer.frame = CGRectMake(0, 0, [self rawWidth], self.bounds.size.height);
-        self.shimmerLabel.frame = CGRectMake(0, 0, [self rawMaskWidth], self.bounds.size.height);
+    @try {
+        BOOL needForceShimmer = !CGSizeEqualToSize(self.bounds.size, self.shimmerLastSize);
+        self.shimmerLastSize = self.bounds.size;
+        
+        // 同步 shimmerLabel 的基本属性
+        self.shimmerLabel.frame = self.bounds;
+        self.shimmerLabel.font = self.font;
+        self.shimmerLabel.textAlignment = self.textAlignment;
+        self.shimmerLabel.numberOfLines = self.numberOfLines;
+        
+        if (self.shimmerConfig.shimmerStyle == ShimmerStyleColorsFlow) {
+            self.shimmerLayer.frame = CGRectMake(-self.shimmerConfig.shimmerWidth, 0,
+                                                 [self rawWidth] + self.shimmerConfig.shimmerWidth * 2,
+                                                 self.bounds.size.height);
+            self.shimmerLabel.frame = CGRectMake(self.shimmerConfig.shimmerWidth, 0,
+                                                 [self rawMaskWidth],
+                                                 self.bounds.size.height);
+        } else {
+            self.shimmerLayer.frame = CGRectMake(0, 0, [self rawWidth], self.bounds.size.height);
+            self.shimmerLabel.frame = CGRectMake(0, 0, [self rawMaskWidth], self.bounds.size.height);
+        }
+        
+        if (self.window && self.shimmerConfig.shimmerStyle != ShimmerStyleNone) {
+            [self startShimmerWithForce:needForceShimmer];
+        }
+    } @catch (NSException *exception) {
+        NSLog(@"MOShimmerLabel layoutSubviews exception: %@", exception);
     }
     
-    if (self.window) {
-        [self startShimmerWithForce:needForceShimmer];
-    }
+    
 }
 
 /// 处理bounds和frame变化

+ 14 - 1
MiMoLive/MiMoLive/Classes/Mine/View/MOMine/MOMianTopCell.m

@@ -127,6 +127,8 @@
         make.height.equalTo(@(MOStarNumViewNormalHeight));
         make.width.equalTo(@(startWidth));
     }];
+    self.nickNameLab.text = GetNickName;
+    self.nickNameLab.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:@"Gilroy"];
 }
 
 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
@@ -221,14 +223,25 @@
     return _audioImgView;
 }
 
+- (void)prepareForReuse {
+    [super prepareForReuse];
+//    [self.nickNameLab prepareForReuse];
+}
+
 #pragma mark - Set
 
 - (void)setMeDataInfo:(MOMeDataInfo *)meDataInfo{
     _meDataInfo = meDataInfo;
     
     [self.headImg sd_setImageWithURL:[NSURL URLWithString:GetAvatar] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"icon_mine_placeHolder"]];
+
     self.nickNameLab.text = meDataInfo.userProfile.nickname;
-    
+//    ShimmerLabelConfig *config = [[ShimmerLabelConfig alloc] init];
+//    config.shimmerStyle = ShimmerStyleColorsFlow;
+//    config.shimmerColorArray = @[[MOTools colorWithHexString:@"#FF3AEA" alpha:1.0],[MOTools colorWithHexString:@"#FF3F31" alpha:1.0],[MOTools colorWithHexString:@"#FFFFFF" alpha:0.8]];
+//    config.shimmerSpeed = 30;
+//    [self.nickNameLab startShimmerWithConfig:config];
+
     NSString *idStr = [NSString stringWithFormat:@"ID: %@",meDataInfo.userProfile.userNo];
     CGFloat idBtnWidth = [MOTools getWidthWithString:idStr font:[UIFont systemFontOfSize:10]] + 25.0;
     

+ 1 - 1
MiMoLive/MiMoLive/Classes/Mine/View/MOMine/MOMineTopCell.h

@@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
 /** 设置按钮 */
 @property (weak, nonatomic) IBOutlet BigBtn *setBtn;
 /** 昵称 */
-@property (weak, nonatomic) IBOutlet UILabel *nickNameLab;
+@property (weak, nonatomic) IBOutlet MOShimmerLabel *nickNameLab;
 @property (weak, nonatomic) IBOutlet UIImageView *genderImg;
 
 

+ 4 - 4
MiMoLive/MiMoLive/Classes/Mine/View/MOMine/MOMineTopCell.xib

@@ -53,8 +53,8 @@
                             <action selector="setBtnClick:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="Q22-Oh-F80"/>
                         </connections>
                     </button>
-                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="LOGO17897665" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UsL-It-DO3">
-                        <rect key="frame" x="99.999999999999986" y="90" width="138.66666666666663" height="25"/>
+                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" " lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UsL-It-DO3" customClass="MOShimmerLabel">
+                        <rect key="frame" x="100" y="90" width="4" height="25"/>
                         <constraints>
                             <constraint firstAttribute="width" relation="lessThanOrEqual" constant="200" id="RKs-7X-ChX"/>
                             <constraint firstAttribute="height" constant="25" id="XyK-hV-U76"/>
@@ -217,7 +217,7 @@
                         </connections>
                     </button>
                     <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="evY-oh-eq7">
-                        <rect key="frame" x="243.66666666666666" y="95" width="14.999999999999972" height="15"/>
+                        <rect key="frame" x="109" y="95" width="15" height="15"/>
                         <constraints>
                             <constraint firstAttribute="width" constant="15" id="5TG-P9-fPV"/>
                             <constraint firstAttribute="height" constant="15" id="nfq-4x-HKH"/>
@@ -289,7 +289,7 @@
                 <outlet property="headImgTop" destination="ZEu-Fg-eeD" id="Bzm-Qb-UsI"/>
                 <outlet property="idBtn" destination="yvc-Ti-gzV" id="Gx6-MF-rAA"/>
                 <outlet property="idBtnWidth" destination="pDm-A7-Nxu" id="9bo-Ey-Wrd"/>
-                <outlet property="nickNameLab" destination="UsL-It-DO3" id="dp7-at-O73"/>
+                <outlet property="nickNameLab" destination="UsL-It-DO3" id="pu8-cu-UN2"/>
                 <outlet property="rightBtn" destination="Cbm-R9-DjE" id="pnk-Jh-azc"/>
                 <outlet property="setBtn" destination="h0Z-ma-TsM" id="x1R-Kx-94e"/>
                 <outlet property="setBtnTop" destination="gO1-ZY-9jX" id="mzK-Fs-zSt"/>