I'm trying to implement zooming for streaming video like in TwitchTV app:
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];
}
}