0

基本上,我有一个显示MPMoviePlayerViewControllerExtended的MainViewController ,并且我想在用户点击主页按钮或电源按钮时关闭MPMoviePlayerViewControllerExtended 。

我在 MPMoviePlayerControllerExtended.m 中试过这个:

-(void)viewWillDisappear {
     [self dismissMoviePlayerViewControllerAnimated];
}
-(void)viewDidDisappear {
     [self dismissMoviePlayerViewControllerAnimated];
}

但它不起作用,显然按下 Home 或 Power 按钮时不会调用它们。

任何帮助表示赞赏。

4

2 回答 2

0

尝试添加:(BOOL)animated

-(void)viewWillDisappear:(BOOL)animated {
     [self dismissMoviePlayerViewControllerAnimated];
}
-(void)viewDidDisappear:(BOOL)animated {
     [self dismissMoviePlayerViewControllerAnimated];
}

也可能想包括

[super viewWillDisappear:animated]

[super viewDidDisappear:animated]

在那些地方

-(void)viewWillDisappear:(BOOL)animated {
     [self dismissMoviePlayerViewControllerAnimated];
     [super viewWillDisappear:animated]
}
-(void)viewDidDisappear:(BOOL)animated {
     [self dismissMoviePlayerViewControllerAnimated];
     [super viewDidDisappear:animated]
}
于 2013-09-19T20:35:32.867 回答
0

由于没有调用这两种方法,我不得不使用通知。

MPMoviePlayerViewControllerExtended.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                          selector:@selector(dismissModalViewControllerAnimated:) 
                                          name:UIApplicationDidEnterBackgroundNotification                  
                                          object:nil];
}
于 2013-09-23T13:24:26.803 回答