2011-11-14 1 views
2

페이지에서 YouTube 동영상을 원하는 앱을 개발하고 있습니다.ios, webview의 Youtube 전체 화면이 회전 중입니다.

-(void)viewDidLoad{ 
    [super viewDidLoad]; 

} 

- (void) viewWillAppear:(BOOL)animated { 
    [self.navigationController setNavigationBarHidden:NO animated:YES]; 
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.47 green:.43 blue:.4 alpha:1]; 

} 

// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    //return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    NSString *htmlString; 
    if(interfaceOrientation == UIInterfaceOrientationPortrait){ 
     htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 20\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"768\" height=\"960\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"768\" height=\"960\"></embed></object></div></body></html>",urlToOpen,urlToOpen]; 

    }else{ 
     htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"1024\" height=\"704\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"1024\" height=\"704\"></embed></object></div></body></html>",urlToOpen,urlToOpen]; 

    } 
    [self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]]; 
    return YES; 
} 

뷰 세로 및 가로 잘 작동 : 그것은 아래의 코드 잘 가지 작동합니다. 문제는 전체 화면과 i 회전으로 비디오를 볼 때입니다. 전체 화면이 끝나면 webview는 회전을 감지하지 못하고 잘못된 방식으로 webview를 인쇄합니다.

YouTube 전체 화면이 내보기를 회전하기 위해 회전하는 것을 어떻게 감지 할 수 있습니까?

감사합니다.

답변

0

설정 콘텐츠 폭

내 템플릿

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \ 
<html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> \ 
<meta name=\"viewport\" content=\"width=320\"> \ 
<style> \ 
html,body {-webkit-text-size-adjust: none; size:100%%} \ 
body {margin: 0; padding: 0;width:100%;} \ 
table { font-family:Georgia; font-size:%dpt; border-style: none; size:100%%} \ 
</style> </head> 

퍼센트 100 ....

-1

오리엔테이션 콜백을 이미 처리하고 있다고 가정하고 있습니까? (shouldAutorotateToInterfaceOrientation, didRotateFromInterfaceOrientation)

YouTube 동영상이 끝나고 포커스가 앱으로 반환되면 viewWillAppear 메서드를 호출해야합니다. 여기에서 기기 방향을 확인할 수 있습니다.

UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; 

그런 다음 레이아웃을 변경합니다. 이 뷰가 처음 열릴 때도 레이아웃을 처리합니다.

당신은 switch 문에서 그것을 할 수 :

switch(orientation) { 
    case UIInterfaceOrientationLandscapeLeft: //layout for this landscape mode 
    case UIInterfaceOrientationPortraitUpsideDown: //layout for this portrait mode 
+0

Thnks 데 도움을줍니다

- (void)moviePlayerDidExitFullScreen { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationPortraitUpsideDown) { [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; } } 

희망이지만도 아니고 정말 올바른. YouTube 전체 화면은 사용자가 비디오를 화면만큼 크게 만드는 두 개의 화살표를 누르면 나타납니다. 그런 다음이 전체 화면으로 회전하고 "완료"를 누르면 화면이 원래 방향으로 유지됩니다. viewWillAppear가 호출되지 않습니다. – ValentiGoClimb

-1

가 나는 것으로 처리 이런 NSNotification을 사용하는 문제

호출됩니다
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlayerDidExitFullScreen) 
              name:@"UIMoviePlayerControllerDidExitFullscreenNotification" 
              object:nil]; 

및 방법은

+0

비공개 API를 사용하면 앱이 중단되거나 거부 될 수 있습니다. – iSaalis

+0

비공개 API? 위의 비공개 API 사용을 볼 수 있습니까? –

+0

UIMoviePlayerControllerDidExitFullscreenNotification은 어디에도 문서화되어 있지 않습니다. OS 업데이트시 변경 될 수 있습니다 ... 또한 문서화되지 않은 알림을 사용하면 거부 될 수 있습니다. – iSaalis