大佬教程收集整理的这篇文章主要介绍了xcode – UIScrollView在添加新子视图时中断,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的问题是,当电影完成/退出并返回到原始屏幕时,UIScrollView中的滚动不起作用.我已经确定了“原因”.当我将MPMoviePlayerViewController object.view添加到self.view子视图时,会发生这种情况.但我不确定如何纠正这个问题.这是我的提炼代码:
.h文件
@interface stuffViewController : UIViewController @property (strong,nonatomiC) IBOutlet UIImageView *imageView; @property (strong,nonatomiC) IBOutlet UIScrollView *scrollView; -(IBACtion) playmovie; -(void) moviePlayBACkDidFinish:(Nsnotification*)notification; @end
.m文件
-(void) viewDidLoad { self.imageView.image = [UIImage imagenamed:@"image.png"]; } -(void) viewDidAppear:(BOOL)animated { self.scrollView.contentSize = self.imageView.image.size; } -(void) playmovie { NSURL *movieURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForresource:@"movietitle" ofType:@"mp4"]]; MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(moviePlayBACkDidFinish:) name:MPMoviePlayerPlayBACkDidFinishNotification object:moviePlayer]; [moviePlayer setMoviesourceType:MPMoviesourceTypeFile]; [[self view] addSubview:moviePlayer.view]; //SCROLLING BREAKS HERE [moviePlayer setFullscreen:YES]; [moviePlayer play]; } -(void)moviePlayBACkDidFinish: (Nsnotification*)notification { MPMoviePlayerController *movieDone = [notification object]; [[NsnotificationCenter defaultCenter] removeObserver:self]; [movieDone.view removeFromSuperview]; [movieDone setFullscreen:NO]; }
我已经通过评论部分确定了罪魁祸首,就像我说的那样,滚动“锁定”在“[[self view] addSubview:moviePlayer.view];”直到我导航到另一个视图然后回来之前,并没有恢复.
对此的任何和所有帮助将不胜感激.
我一直在使用MPMoviePlayerController.但是,在切换到MPMoviePlayerViewController时,一些有趣的事情一直在发生.
这是改变了 – (void)playmovie
-(void) playmovie { self.scrollView.contentOffset = CGPointZero; NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForresource:@R_527_10586@ltitle ofType:@"mp4"]]; MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; [self presentMoviePlayerViewControllerAnimated:playerController]; playerController.moviePlayer.moviesourceType = MPMoviesourceTypeFile; [playerController.moviePlayer play]; playerController = nil; }
有趣的是,UIScrollView仍然可以正常工作,如果它完全向下滚动它将无法再从电影开始时的位置向上滚动.我通过在PLaymovie的开头添加self.scrollView.contentOffset = CGPointZero来修复此问题,以告诉scrollView移动到顶部(因此上面没有任何内容可以滚动回去).我假设在viewDidAppear中的代码中添加某种if语句会使scrollView.contentSize不能重新执行,这可能会解决无法向上滚动的问题,但是我喜欢它的“清洁度”顶端.
最后一个问题.像这样使用MPMoviePlayerViewController在MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url]时,会在我的调试器中弹出一些有趣的错误.行已执行.它们如下:
Oct 25 10:25:51 Compy.local AppName[14590] <Error>: CGContextSaveGState: invalid context 0x0 Oct 25 10:25:51 Compy.local AppName[14590] <Error>: CGContextClipToRect: invalid context 0x0 Oct 25 10:25:51 Compy.local AppName[14590] <Error>: CGContextTranslateCTM: invalid context 0x0 Oct 25 10:25:51 Compy.local AppName[14590] <Error>: CGContextDrawShading: invalid context 0x0 Oct 25 10:25:51 Compy.local AppName[14590] <Error>: CGContextRestoreGState: invalid context 0x0
它似乎没有破坏任何东西.然而,当谈到错误的错误陈述时,我倾向于成为完美主义者.我已经对这些错误进行过一些研究,但是我没有找到任何合适的东西可以在这种情况下发挥作用.
感谢目前为止所有的帮助!我再一次感谢任何和所有帮助.
@H_909_25@mPMoviePlayerController *movieDone = [notification object];
同
@H_909_25@mPMoviePlayerController *movieDone = (MPMoviewPlayerController *)[notification object];
并且还添加
@H_909_25@movieDone = nil;
要确保从superView中完全@L_724_25@mPMoviePlayerController,请尝试在视频完成播放后按下视图上的按钮(在@L_835_6@mPMoviePlayerController之前创建)并查看它是否会触发.导航控制器必须以模态方式呈现您的MPMoviewPlayerController或进行推送.如果是模态显示,请在播放结束时尝试将其解除.
以上是大佬教程为你收集整理的xcode – UIScrollView在添加新子视图时中断全部内容,希望文章能够帮你解决xcode – UIScrollView在添加新子视图时中断所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。