新增手势识别功能以处理背景和内容区域的点击事件,确保用户体验流畅。重写 removeFromSuperview 方法以停止 MP4 播放并释放资源,添加 dealloc 方法以确保资源正确释放,保持代码结构一致性。

This commit is contained in:
edwinQQQ
2025-06-18 19:00:01 +08:00
parent 887bb19056
commit c1b9dd3d9f

View File

@@ -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