2011-08-03 3 views
2

UIWebViewで埋め込みビデオプレーヤーの向きを管理するために、いくつかのCSSを作成したいと考えています。そして、これらのCSSは、デバイスの向きに応じてプレーヤーのサイズを変更するように動作します。CSSを使用して埋め込みプレーヤーの高さと幅を再設定するにはどうすればよいですか?

iPhone/iPadで次のコードを実行するには、iPhoneアプリケーションでCSSを作成して追加するにはどうすればよいですか?

<link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css"> 
    <link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css"> 

EDIT:私は、埋め込みビデオのために行っているコードです(。* youTubePlayerはのUIWebViewのインスタンスである)

NSString* embedHTML = @"<html><head><style=\"margin:0\" link rel=\"stylesheet\" media=\"all and (orientation:portrait)\" href=\"portrait.css\">" 
    "<link rel=\"stylesheet\" media=\"all and (orientation:landscape)\" href=\"landscape.css\">" 
    "</style></head>" 
    "<body embed id=\"yt\" src=\"%@\"type=\"application/x-shockwave-flash\"></embed>" 
    "</body></html>"; 
    NSString* html = [NSString stringWithFormat:embedHTML, url]; 
    NSString *path = [[NSBundle mainBundle] bundlePath]; 
    NSURL *baseURL = [NSURL fileURLWithPath:path]; 
    [youTubePlayer loadHTMLString:html baseURL:baseURL]; 

風景を追加した後

.css 本文 { 幅:1002; 身長:768; }

portrait.css 体 {幅:768。 高さ:1024; }

正しく動作していないにもかかわらず、コードに何が間違っているか教えてください。

答えて

0

あなたの幅と高さの後にpxがありませんか?例:portrait.css body {width:768px;高さ:1024px; }の代わりにportrait.css本体{幅:768;高さ:1024; }

+0

'PX' はCSSの効果を実現するために違いがありません。 –

1

最後に私の目的地に到達し、次のコードで問題を整理しました。 YouTubeのビデオやUIWebviewのオリエンテーションを設定するのに最適です。次のコードの利点は、デバイスの向きの変更についてビデオを再起動しないことです。

NSString* embedHTML = @"<html><head><link rel=\"stylesheet\" media=\"all and (orientation:portrait)\" href=\"portrait-ipad.css\"><link rel=\"stylesheet\" media=\"all and (orientation:landscape)\" href=\"landscape-ipad.css\"></head><body><iframe type=\"text/html\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\"></iframe></body></html>"; 
    NSString *videoID = [url stringByReplacingOccurrencesOfString:@"http://www.youtube.com/watch?v=" withString:@""]; 
    videoID = [videoID stringByReplacingOccurrencesOfString:@"&feature=youtube_gdata" withString:@""]; 
    html = [NSString stringWithFormat:embedHTML, videoID];  
    NSString *path = [[NSBundle mainBundle] bundlePath]; 
    NSURL *baseURL = [NSURL fileURLWithPath:path]; 
    [youTubePlayer loadHTMLString:html baseURL:baseURL]; 

(youTubePlayerがのUIWebViewのインスタンスである。)

関連する問題