Allow video on landscape with only-portrait app

前端 未结 8 1398
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 06:35

I have a UIWebView included in a UIViewController which is a descendant of UINavigationController. It looks like this:

8条回答
  •  庸人自扰
    2020-12-13 07:04

    My answer on this question works great. Here It will play the video inside your WebView normally but if you tilt your phone it will play in Landscape!

    Also important to note is if you include youtube.com as the Base URL it will load much quicker.

    Make a UIWebView in your storyboard and connect the @property to it, then reference below.

        CGFloat width = self.webView.frame.size.height;
        CGFloat height = self.webView.frame.size.width;
        NSString *youTubeVideoCode = @"dQw4w9WgXcQ";
        NSString *embedHTML = @"";
        NSString *html = [NSString stringWithFormat:embedHTML, width, height, youTubeVideoCode];
        self.webView.scrollView.bounces = NO;
        [self.webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];
    

提交回复
热议问题