UIScrollView内部的MPMoviePlayerController缩放问题

时间:2014-05-26 17:29:08

标签: ios uiscrollview zoom mpmovieplayercontroller

我正在尝试像TwitchTV app中那样实现流式视频的缩放:

TwitchTV

应该是非常明确的。我有一个滚动视图,我添加内容视图,作为所有需要缩放的子视图的容器。它适用于简单的UIViews或UIImageViews:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.jpg"]];
    [self.imageView setFrame:self.scrollView.bounds];

    self.contentView = [[UIView alloc] init];
    [self.contentView setFrame:self.scrollView.bounds];
    [self.contentView addSubview:self.imageView];    
    [self.scrollView addSubview:self.contentView];  

    self.scrollView.minimumZoomScale = 0.5;
    self.scrollView.maximumZoomScale = 1.0;
    self.scrollView.delegate = self;    
    self.scrollView.zoomScale = 1.0;     
}

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.contentView;
}

但是,如果我将MPMoviePlayerController的视图添加为contentView的子视图,则它无法正确缩放。如果scrollView的contentSize等于其边界,则缩放到缩放不起作用,并且仅当我在scrollView滚动时捏合时它才起作用。有什么问题?

以下是我初始化MPMoviePlayerController的方法:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Initialize contentView

    [self setupMovie];
    [self.contentView addSubview:self.moviePlayerController.view];
    [self.scrollView addSubview:self.contentView];

    // Zoomscale stuff etc
}

- (void)setupMovie
{
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:self.movieURL];

    if (player)
    {
        self.moviePlayerController = player;        
        [player setContentURL:movieURL];
        [player setMovieSourceType:MPMovieSourceTypeStreaming];
        [player.view setFrame:self.contentView.bounds];        
        [player view].backgroundColor = [UIColor blackColor];
    }
}

1 个答案:

答案 0 :(得分:0)

找到解决方案,如果有人有兴趣的话。

如果您将其添加为scrollView'w子视图,看起来UIScrollView缩放行为与MPMoviePlayerController的视图的捏合手势识别器冲突。因此,如果您不需要,可以删除此识别器:

MPMoviePlayerController *player;

[[[player view] subviews] enumerateObjectsUsingBlock:^(id view, NSUInteger idx, BOOL *stop) {
        [[view gestureRecognizers] enumerateObjectsUsingBlock:^(id pinch, NSUInteger idx, BOOL *stop) {
            if([pinch isKindOfClass:[UIPinchGestureRecognizer class]]) {
                [view removeGestureRecognizer:pinch];
            }
        }];
    }];