2011-11-14 55 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; 
} 

工作在縱向和橫向細的觀點。 問題是,當我看到全屏和我旋轉的視頻。當我完成整個屏幕時,webview沒有檢測到旋轉並以錯誤的方式打印webview。

我怎麼能檢測到Youtube全屏旋轉旋轉我的看法?

Thankyou

回答

0

集內容寬度爲100%

我的模板

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

....

-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但它也不是真正正確的。 youtube全屏幕是當用戶推動使得視頻像屏幕一樣大的兩個箭頭時。然後,當您使用此全屏旋轉並按下「完成」時,屏幕會保持原始方向。 viewWillAppear不被調用。 – ValentiGoClimb

-1

我處理這使用NSNotification這樣的問題

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlayerDidExitFullScreen) 
              name:@"UIMoviePlayerControllerDidExitFullscreenNotification" 
              object:nil]; 

和方法將被稱爲是

- (void)moviePlayerDidExitFullScreen 
{ 
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 

    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; 
    } 
} 

希望幫助

+0

私有API使用可能會破壞您的應用程序或導致拒絕。 – iSaalis

+0

私有API?你能看到上面的私有api用法嗎? –

+0

UIMoviePlayerControllerDidExitFullscreenNotification沒有記錄在任何地方。所以,它可以在操作系統更新中進行更改......另外,使用未公開的通知可能會導致拒絕。 – iSaalis