How to change embed video size while playing in UIWebView?

人盡茶涼 提交于 2019-12-24 07:26:50

问题


I have a UIWebView with size 250x160, which should play video from youtube.com.

NSString *videoURL = @"http://www.youtube.com/v/Y4Y_a45Bv20?version=3&f=videos&app=youtube_gdata";
        NSString *videoHTML = [NSString stringWithFormat:@"\
                               <html><body>\
                               <embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"%f\" height=\"%f\">\
                               </embed>\
                               </body></html>", videoURL, self.web.frame.size.width-20, self.web.frame.size.height-20];


        [self.web loadHTMLString: videoHTML baseURL: nil];

While playing video I want to resize the UIWebView. When I make it, for example 2 times bigger, embed video stays how it was 250x160. How can I resize it without restarting it?


回答1:


try affineTransform.

webview.transform = CGAffineTransformMakeScale(2, 2);

or

webView.scalesPageToFit=YES;



回答2:


I found anoyingly easy solution :

NSString *videoHTML = [NSString stringWithFormat:@"<iframe class=\"youtube-player\" type=\"text/html\" width=\"100%%\" height=\"98%%\" src=\"http://www.youtube.com/embed/Y4Y_a45Bv20?showinfo=0\" frameborder=\"0\"></iframe>"];

The key is in width=\"100%%\" and height=\"98%%\". I didn't set height to 100%%, because while playing video, it's strangely increases and after 10-20 seconds you need to scroll uiwebview to find where video is gone.

And don't forget set UIWebView scalePageToFit = YES;




回答3:


I found this approach and it worked for me:

webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

Auto-resize iOS WebView Helper



来源:https://stackoverflow.com/questions/20956261/how-to-change-embed-video-size-while-playing-in-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!