在iOS4 for iPhone 4 / 3GS中,我有一个tableview,其中一个单元格播放一个电影文件。如果电影完成播放并且控件已消失,则视图将返回状态栏下方。就像在这张图片中......我太新了,无法发布。在这里看到......
http://www.dezignwright.com/ios4_movie.png
如果电影结束时控件处于开启状态,则没有问题。
奖励:如何在开始播放时强制电影播放器进入风景。我根本不希望它以肖像形式播放。
感谢。
答案 0 :(得分:1)
步骤1.保存包含将启动MPMoviePlayerViewController的视图的superview框架。
步骤2.为playbackDidFinishNotification附加一个监听器
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
步骤3.在通知处理程序中将帧重置回原始帧,但是在延迟之后允许动画完成。如果在动画期间修改了帧,则它无效。
[self performSelector:@selector(resetFrame)
withObject:nil
afterDelay:kResetFrameDelay];
- (void)resetFrame {
self.view.frame = kApplicationFrame;
}
答案 1 :(得分:1)
此问题已得到解决,不再是iOS 4.3中的问题。
感谢每个人的投入。
答案 2 :(得分:0)
这似乎是4.0中的错误,它在使用“完成”按钮退出时正常工作。
我使用的解决方法是手动存储框架,然后在收到MPMoviePlayerPlaybackDidFinishNotification
时将其恢复。
最后要以横向模式获取它,请使用MPMoviePlayerViewController
的子类覆盖shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
即。像这样的东西:
@interface CustomMoviePlayerViewController : MPMoviePlayerViewController
@end
@implementation CustomMoviePlayerViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft;
}
@end
在你的控制器中解决这个问题:
- (void)playbackEnded:(NSNotification *)notification
{
[[self view] setFrame:[self originalFrame]];
}
- (void)playMovie:(NSString *)movieURLString
{
MPMoviePlayerViewController *controller = [[CustomMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:movieURLString]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackEnded:) name:MPMoviePlayerPlaybackDidFinishNotification object:[controller moviePlayer]];
[self presentMoviePlayerViewControllerAnimated:controller];
}
答案 3 :(得分:0)
我通过在我启动电影播放器之前明确声明我在原始视图中不使用全屏布局来解决这个问题:
-(IBAction)playMovieButtonPressed:(id)sender {
MPMoviePlayerViewController* playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[self localMovieURL]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerViewController.moviePlayer];
[self setWantsFullScreenLayout:NO];
// this ensures that the original frame is restored correctly
// if the movie ends and the player is closed automatically
[self presentMoviePlayerViewControllerAnimated:playerViewController];
[playerViewController release];
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
}
答案 4 :(得分:0)
我遇到了同样的问题,我用这个workaroud来解决这个问题:
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
CGRect frame = CGRectMake(0, 20, 768, 1004);
self.view.frame = frame;
}else {
CGRect frame = CGRectMake(0, 20, 1004, 768);
self.view.frame = frame;
}
}
将Rect调整为屏幕大小,我的代码适用于iPad。