2011-06-21 23 views
3

我有一個UIWebView,充滿這樣:自動旋轉視頻從一個UIWebView發揮到風景模式

[myWebView loadHTMLString:@"<iframe src=\"http://www.youtube.com/embed/grTCDFbhKMU\" frameborder=\"0\" allowfullscreen></iframe>" 
baseURL:nil]; 

視頻被正確啓動,但它無法切換到橫向模式。

我已經在關注的ViewController寫這個?

- (void)didRotate:(NSNotification *)notification 
{ 
    UIDeviceOrientation orientation = [[notification object] orientation]; 

    if (orientation == UIDeviceOrientationLandscapeLeft) 
    { 
     [self.newsContent setTransform:CGAffineTransformMakeRotation(M_PI/2.0)]; 
    } 
    else if (orientation == UIDeviceOrientationLandscapeRight) 
    { 
     [self.newsContent setTransform:CGAffineTransformMakeRotation(M_PI/-2.0)]; 
    } 
    else if (orientation == UIDeviceOrientationPortraitUpsideDown) 
    { 
     [self.newsContent setTransform:CGAffineTransformMakeRotation(M_PI)]; 
    } 
    else if (orientation == UIDeviceOrientationPortrait) 
    { 
     [self.newsContent setTransform:CGAffineTransformMakeRotation(0.0)]; 
    } 
} 

有用的改變內容方向,但usesless一旦視頻推出:(

任何想法

+0

同樣的問題爲什麼,webView不能在橫向模式下從YouTube播放視頻...我試過子類webview用於旋轉到landsc的方法 –

回答

0

你應該返回YES以下方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    //All orientations are accepted except for the upsidedown orientation 
    if(interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown) { 
     return YES; 
    } else { 
     return NO; 
    } 
} 

如果是返回編輯它將旋轉,如果沒有被返回,它將不會旋轉。

+1

我已經試過了。它不起作用。此外,我讀過的這個方法必須爲應用程序中的每個ViewController實現,以使其工作。而且我不想自動控制整個應用程序。 –

+0

如果您不想旋轉,則可以在其他情況下返回NO。然而,它使用後,它爲我旋轉。 – Manuel

+0

當然,我的錯誤。我會嘗試。 –