diff --git a/YuMi/Modules/YMMine/View/Medals/MedalsDetailView.m b/YuMi/Modules/YMMine/View/Medals/MedalsDetailView.m index f7ed9792..09b7e680 100644 --- a/YuMi/Modules/YMMine/View/Medals/MedalsDetailView.m +++ b/YuMi/Modules/YMMine/View/Medals/MedalsDetailView.m @@ -103,6 +103,28 @@ } } }; + + // 添加点击手势识别器,用于点击背景空白处移除视图 + UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleBackgroundTap:)]; + [self addGestureRecognizer:tapGesture]; + + // 为内容区域添加手势识别器,防止点击内容区域时关闭视图 + UIView *contentArea = [[UIView alloc] init]; + contentArea.backgroundColor = [UIColor clearColor]; + [self addSubview:contentArea]; + [contentArea mas_makeConstraints:^(MASConstraintMaker *make) { + make.center.mas_equalTo(self); + make.width.mas_equalTo(280); + make.top.mas_equalTo(self.imageView).offset(-20); + // make.bottom.mas_equalTo(self.levelIndicatorView).offset(20); + make.height.mas_equalTo(360); + }]; + + UITapGestureRecognizer *contentTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleContentTap:)]; + [contentArea addGestureRecognizer:contentTapGesture]; + + // 设置手势优先级,确保内容区域的手势优先处理 + [tapGesture requireGestureRecognizerToFail:contentTapGesture]; } - (void)setDetailItemVo:(MedalSeriesVo *)detailItemVo { @@ -216,4 +238,33 @@ return _mp4View; } +// 添加处理背景点击的方法 +- (void)handleBackgroundTap:(UITapGestureRecognizer *)gesture { + [self removeFromSuperview]; +} + +// 添加处理内容区域点击的方法(仅用于阻止背景点击事件) +- (void)handleContentTap:(UITapGestureRecognizer *)gesture { + // 什么都不做,只是阻止事件传递 +} + +// 重写 removeFromSuperview 方法,确保在移除前停止 MP4 播放 +- (void)removeFromSuperview { + // 停止 MP4 播放并释放资源 + [self stopMP4Playback]; + self.mp4Parser = nil; + + [super removeFromSuperview]; +} + +// 添加 dealloc 方法确保资源被正确释放 +- (void)dealloc { + // 停止 MP4 播放 + [self stopMP4Playback]; + + // 清理资源 + self.mp4Parser = nil; + NSLog(@"MedalsDetailView dealloc"); +} + @end