あなたの助けが必要です。ScrollView
いくつかの で水平を作成したいAVPlayers
。ScrollView
いくつかの写真でこれを試してみましたが、うまくいきます。今の問題は、スクロールできることですView
が、すべてがAVPlayerViews
同じ位置にあるため、最後にロードされたビデオを見ることができ、他のすべてのスクロール位置は空白です。
これは私のクラスのソースです:
@implementation VPVideoScroller
const CGFloat kScrollObjHeight = 748.0;
const CGFloat kScrollObjWidth = 1024.0;
NSUInteger numImages = 0;
- (void)viewDidLoad
{
numImages = _pictureArray.count;
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
// 1. setup the scrollview for multiple images and add it to the view controller
self.scrollView.clipsToBounds = YES;
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= numImages; i++)
{
if (i<3) {
/*
//------------
MPMediaItem *item = [self.pictureArray objectAtIndex:(i-1)];
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
*/
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:self.currentURL];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
//------------
UIView *imageView = [[UIView alloc] init];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
[player play];
/*
UIImage *image = [self.pictureArray objectAtIndex:(i-1)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
*/
// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i; // tag our images for later use when we place them in serial fashion
imageView.contentMode = UIViewContentModeScaleAspectFit;
[imageView.layer addSublayer:playerLayer];
playerLayer.frame = imageView.layer.bounds;
[self.scrollView addSubview:imageView];
}
}
[self layoutScrollImages]; // now place the photos in serial layout within the scrollview
}
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [self.scrollView subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
//[self.scrollView setContentSize:CGSizeMake((numImages * kScrollObjWidth), [self.scrollView bounds].size.height)];
[self.scrollView setContentSize:CGSizeMake((numImages * kScrollObjWidth), kScrollObjHeight)];
}
にはのURLpictureArray
が含まれていArray
ますが、それらはすべて同じです。したがってAVPlayers
、すべて同じビデオを表示する必要があります。
前もって感謝します。ケビン