如何在iPhone应用程序中重叠视频?

时间:2014-02-23 03:52:18

标签: iphone objective-c

我正在制作一款播放可重叠视频的iPhone应用。像这样:

enter image description here

我该怎么做?

1 个答案:

答案 0 :(得分:0)

使用UICollectionView

1)效率低下:如果你想同时播放所有媒体。 网格视图的媒体播放器。


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView     cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CollectionCell forIndexPath:indexPath];

    // get URL 
    Player *mediaPlayer = [[self playerArray]objectAtIndex:indexPath.row];

    NSURL* videoURL = [NSURL URLWithString:mediaPlayer.url];
    MPMoviePlayerController* mPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
    [mPlayer prepareToPlay];
    [mPlayer play];

    //For viewing partially.....
    [mPlayer.view setFrame:CGRectMake(/*Your frame*/)];
    [mPlayer.view.backgroundColor = [UIColor grayColor]; 
    [cell addSubview:mPlayer.view];  

    return cell;

}

2)高效方式:使用缩略图放置网格,并在用户点击单元格时将媒体播放器对象替换为UIImageview(在这种情况下将上面的代码放在didSelectRow中)