0

I have an application which only supports portrait mode which has a table, each cell containing a title and a webview with the YouTube video.

Now how would you go bout making the Youtube player be both in landscape AND portrait mode?

    [cell.titleLabel setText:[[[StoreVars sharedInstance].sharedArrayOfVideo objectAtIndex:indexPath.row] objectForKey:@"title"]];
    NSString *ID = [[[StoreVars sharedInstance].sharedArrayOfVideo objectAtIndex:indexPath.row] objectForKey:@"id"];
    NSString *code = [NSString stringWithFormat:@"<iframe width=\"280\" height=\"170\" src=\"//www.youtube.com/embed/%@\" frameborder=\"0\" allowfullscreen></iframe>",ID];
    NSLog(@"Loading video: %@",code);
    [cell.videoWebView loadHTMLString:code baseURL:[NSURL URLWithString:@"http:"]];
    [cell.videoWebView.scrollView setScrollEnabled:NO];
    [cell.videoWebView.scrollView setBounces:NO];

I've searched around and found a code like this, but I can't access the cells webview.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(webView && webView.superView) return YES;
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76

1 Answers1

0

If you are developing for iOS 6.0 and later, I recommend using -supportedInterfaceOrientations

However, I would not recommend using this method to rotate the cells, as I am pretty sure it wont be called all the time the device is changing it's orientation (especially if the parent controller is disabling landscape already). You may try to listen to UIDeviceOrientationDidChangeNotification within your (subclass) cell to rotate the webview and within your view controller (with the table view) and run a -reloadData on your table view in order to properly resize the cells (assuming the landscape webview is way higher than the portrait webview)

Markus
  • 585
  • 7
  • 18
  • Um.... Either I didn't understand your answer or you missed something. When clicking the webView (only contains an embedded video), it opens the YouTube player WHICH needs to be able to rotate. As far as I can tell, I can't access the view controller of that. – Lord Zsolt Aug 21 '13 at 08:12
  • No you didn't miss something, but i did. I simply misunderstood the question. Are you talking about the system video player here? – Markus Aug 21 '13 at 08:14
  • Yes, I would assume that's what loads the video. – Lord Zsolt Aug 21 '13 at 08:16
  • If you are not attempting to display the video fullscreen (the system player https://developer.apple.com/library/ios/DOCUMENTATION/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html would be capable of doing this) it may still work with the solution i posted above, since i would guess that the video player is presenting the video view on top of the webview (which you are rotating with the orientation changing notifications). It's just a guess. You may find (way) better solutions here: – Markus Aug 21 '13 at 08:26
  • http://stackoverflow.com/questions/5014176/mpmoviewplayercontroller-fullscreen-playback-rotation-with-underlying-uiviewcont or here http://stackoverflow.com/questions/13011266/mpmovieplayercontroller-should-only-in-landscape-mode – Markus Aug 21 '13 at 08:27