滚动视图中的问题

发布于 2024-12-11 00:16:57 字数 1826 浏览 0 评论 0原文

我有一个 UIScrollView,需要在其中添加两个视频,但我面临以下问题:

*我有一个有两个页面的滚动视图。如果我只在第一个视频中添加一个,它就可以正常工作。在第一页中我将拥有视频,第二个将是空的。

*如果我尝试添加两个视频 - 滚动视图的第一页将为空,第二页将包含第二个视频。

无论我如何行动,我都无法在滚动视图中同时显示两个视频。

这就是我所做的:

 scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];


scrollView.pagingEnabled = YES;

NSString *path1 = [[NSBundle mainBundle] pathForResource:@"video1" ofType:@"mp4"];
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"video2" ofType:@"mp4"];

videoPlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path1]];
videoPlayer2 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path2]];

[[videoPlayer1 view] setFrame:CGRectMake(0, 0, 320, 335)];
[videoPlayer1 prepareToPlay];


[videoPlayer1 setControlStyle:MPMovieControlStyleDefault];
videoPlayer1.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[self.scrollView addSubview:[videoPlayer1 view]];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer1];

[[videoPlayer2 view] setFrame:CGRectMake(320, 0, 320, 335)];
[videoPlayer2 prepareToPlay];

[videoPlayer2 setControlStyle:MPMovieControlStyleDefault];
videoPlayer2.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[self.scrollView addSubview:[videoPlayer2 view]];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:
 MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer2];

scrollView.contentSize = CGSizeMake(640, 400);
[self.view addSubview:scrollView];

请帮忙。谢谢

I have a UIScrollView in which I need to add two videos, but I'm facing the following issue:

*I have a scrollView with two pages.If I add only one the first video, it works ok.In the first page of the scrollView I'll have the video and the second one will be empty.

*If I try to add both videos-the first page of the scrollView it will be empty and the scond one will contain the second video.

No matter how I act I cannot have both videos in the scrollView.

Here is what I did:

 scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];


scrollView.pagingEnabled = YES;

NSString *path1 = [[NSBundle mainBundle] pathForResource:@"video1" ofType:@"mp4"];
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"video2" ofType:@"mp4"];

videoPlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path1]];
videoPlayer2 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path2]];

[[videoPlayer1 view] setFrame:CGRectMake(0, 0, 320, 335)];
[videoPlayer1 prepareToPlay];


[videoPlayer1 setControlStyle:MPMovieControlStyleDefault];
videoPlayer1.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[self.scrollView addSubview:[videoPlayer1 view]];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer1];

[[videoPlayer2 view] setFrame:CGRectMake(320, 0, 320, 335)];
[videoPlayer2 prepareToPlay];

[videoPlayer2 setControlStyle:MPMovieControlStyleDefault];
videoPlayer2.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[self.scrollView addSubview:[videoPlayer2 view]];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:
 MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer2];

scrollView.contentSize = CGSizeMake(640, 400);
[self.view addSubview:scrollView];

Please help.thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文