基本上,我有一个 MainViewController ,它提供了一个 MPMoviePlayerViewControllerExtended ,当用户点击主页按钮或电源按钮时,我想解除 MPMoviePlayerViewControllerExtended 。
我在MPMoviePlayerControllerExtended.m中试过这个:
-(void)viewWillDisappear {
[self dismissMoviePlayerViewControllerAnimated];
}
-(void)viewDidDisappear {
[self dismissMoviePlayerViewControllerAnimated];
}
但它不起作用,显然当按下Home或Power按钮时不会调用它们。
感谢任何帮助。
答案 0 :(得分: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]
}
答案 1 :(得分:0)
由于未调用这两种方法,我不得不使用通知。
在 MPMoviePlayerViewControllerExtended.m
中- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dismissModalViewControllerAnimated:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
}