0
#import "ViewController.h"

@implementation ViewController
@synthesize scrollView;

- (void)viewDidLoad
{
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

    [self.view addSubview:scrollView];
    scrollView.contentSize = CGSizeMake(4096, 768);


    NSString *url = [[NSBundle mainBundle] pathForResource:@"F0" ofType:@"mov"];

    player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                          selector:@selector(movieFinishedCallback) 
                                          name:MPMoviePlayerPlaybackDidFinishNotification 
                                          object:player];
    player.view.frame = CGRectMake(0, 0, 1024, 768);
    player.scalingMode = MPMovieScalingModeAspectFill;
    [scrollView addSubview:player.view];
    [player play];

    UIImageView *image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"29-30-p1.jpg"]];
    image1.frame = CGRectMake(1024,0,1024,768);
    image1.clipsToBounds = YES;
    [scrollView addSubview:image1];
    image1.animationImages = eyeFrames;
    image1.animationDuration = 0.25;
    image1.animationRepeatCount = 1;

    UIImageView *image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"29-30-p2.jpg"]];
    image2.frame = CGRectMake(2048,0,1024,768);
    image2.clipsToBounds = YES;
    [scrollView addSubview:image2];

    UIImageView *image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"29-30-p3.jpg"]];
    image3.frame = CGRectMake(3072,0,1024,768);
    image3.clipsToBounds = YES;
    [scrollView addSubview:image3];


    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void) movieFinishedCallback:(NSNotification *) aNotification{
     MPMoviePlayerController *moviePlayer = [aNotification object];
     [[NSNotificationCenter defaultCenter] removeObserver:self
                                           name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:moviePlayer];
    [moviePlayer.view removeFromSuperview];
    [player release];

}

-(void)viewWillDisappear:(BOOL)animated{

    //NSLog(@"x=%f",scrollView.contentOffset.x);
    [player stop];

}

-(void)viewWillAppear:(BOOL)animated{
    [player play];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

@end

viewWillDisappearみんな、 andviewWillAppearループが機能しない理由がわかりません。スクロールするとビデオを停止し、スクロールバックすると再生を続けたい。うまくいかない理由を教えてください。ところで、ビデオが終了したときにプログラムが終了する理由がわかりません。以前のプロジェクトで同じコードを使用しましたが、エラーは表示されませんでした。少し混乱します。some1が私を助けてくれることを願っています。前もって感謝します。

4

1 に答える 1

1

Uが与えたscrollView.contentSize = CGSizeMake(4096, 768);これは、スクロールしてもビューが消えたり現れたりしないことを意味します.スクロールは位置的に消えたり現れたりします.実際にはスクロールが表示されます.フレームのフレームplayerとスクロール移動位置が表示されたときにプレーヤーの位置を再生し、プレーヤーのフレームを横切ると停止しますscrollViewDidScroll

于 2012-04-06T12:43:04.050 に答える