0
votes

I'm trying to implement zooming for streaming video like in TwitchTV app:

TwitchTV

Should be pretty straitforward. I have a scroll view, to which I add content view which serves as a container for all subviews that need to be zoomed. It works properly with simple UIViews or 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;
}

However, if I add MPMoviePlayerController's view as a subview of contentView it does not zoom properly. Pinch to zoom just doesn't work if scrollView's contentSize is equal to its bounds, and it works ONLY if I pinch while scrollView is scrolling. What's the problem?

Here is how I initialize my 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

1 Answers

0
votes

Found solution, if anyone is interested.

Looks like UIScrollView zooming behavior conflicts with MPMoviePlayerController's view's pinch gesture recognizer if you add it as scrollView'w subview. So you can remove this recognizer if you don't need it:

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];
            }
        }];
    }];