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"> 

편집

:

다음은 내가 포함 된 비디오에 대해 수행 한 코드 풍경을 추가 한도

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]; 

(*은 YouTubePlayer가있는 UIWebView의 인스턴스입니다.) 그리고. .css 본문 { 너비 : 1002; 신장 : 768; }

portrait.css 본체 { 폭 : 768; 신장 : 1024; }

제대로 작동하지 않더라도. 코드가 잘못되었습니다. 알려주세요.

답변

0

너비와 높이가 지난 후 px가 누락 되었습니까? 예 : portrait.css 본문 {width : 768px; 높이 : 1024px; } 대신 portrait.css body {width : 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의 인스턴스입니다.)

관련 문제