4

私のプロジェクトでは、ストーリーボードを使用せずにビューを手動で作成しています。画像をタップするとビデオを再生しようとしました。それは正常に動作します。しかし、画像をタップするとメモリリークが発生することを確認するたびに、これについて多くのことを検索して適用しましたが、役に立ちませんでした。私の 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: メソッドに入るたびにメモリ リークが発生します。どんな助けでも大歓迎です。

4

3 に答える 3

1

私は問題を発見しました.iPad(iOSバージョン5)のデバイスにあります。iPad4(iOSバージョン7)で確認したところ、リークはありませんでした。

于 2013-10-23T12:56:41.200 に答える
1
@property (strong, nonatomic) MPMoviePlayerController *theMoviePlayer;
@property (weak, nonatomic) UIImageView *image1;

別の考えでは、あなたtheMoviePlayerは削除されていません。ビューを透明にして、新しいビューの背後で既に機能しているかどうかを確認してください

于 2013-10-22T11:10:20.813 に答える