在我的项目中,我手动创建视图而不使用情节提要。当我点击图像时,我尝试播放视频。它工作正常。但是每次当我检查它时点击图像时都会显示内存泄漏,我已经搜索了很多并应用了但没有用。在我的 Appdelegate.h 文件中:
@property (strong, nonatomic) MPMoviePlayerController *theMoviePlayer;
@property (strong, nonatomic) UIImageView *image1;
在 .m 文件中:
-(void) startPage{
.....
_image1 = [[UIImageView alloc] initWithFrame:CGRectMake((self.window.frame.size.width/2)-25, 40, 50, 50)];
[_image1 setUserInteractionEnabled:YES];
_image1.image = [UIImage imageNamed:@"image_2.jpg"];
_tapImage1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(image1Tapped:)];
[_image1 addGestureRecognizer:_tapImage1];
.....}
在 imageTapped() 中,
-(void) image1Tapped:(UITapGestureRecognizer *)sender
{
.....
[_image1 removeFromSuperview];
_theMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[_theMoviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[_theMoviePlayer.view setFrame:CGRectMake(0,-55, self.window.frame.size.width, self.window.frame.size.height)];
[_theMoviePlayer setScalingMode:MPMovieScalingModeAspectFill];
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[backgroundWindow addSubview:_theMoviePlayer.view];
[_theMoviePlayer.view bringSubviewToFront:backgroundWindow];
[_theMoviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification object:_theMoviePlayer];
...}
每次进入 imageTapped: 方法时都会发生内存泄漏。任何帮助将不胜感激。