From c1b9dd3d9f0108bdbbcc2dbc4df782187c69427a Mon Sep 17 00:00:00 2001 From: edwinQQQ Date: Wed, 18 Jun 2025 19:00:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=8B=E5=8A=BF=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=8A=9F=E8=83=BD=E4=BB=A5=E5=A4=84=E7=90=86=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E5=92=8C=E5=86=85=E5=AE=B9=E5=8C=BA=E5=9F=9F=E7=9A=84?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E4=BA=8B=E4=BB=B6=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C=E6=B5=81=E7=95=85=E3=80=82?= =?UTF-8?q?=E9=87=8D=E5=86=99=20removeFromSuperview=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BB=A5=E5=81=9C=E6=AD=A2=20MP4=20=E6=92=AD=E6=94=BE=E5=B9=B6?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E8=B5=84=E6=BA=90=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20dealloc=20=E6=96=B9=E6=B3=95=E4=BB=A5=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=AD=A3=E7=A1=AE=E9=87=8A=E6=94=BE=EF=BC=8C?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../YMMine/View/Medals/MedalsDetailView.m | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) 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