2011-11-14 4 views
2

私は、私が開発しているアプリです。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のフルスクリーンは、ユーザーがビデオを画面と同じ大きさにする2本の矢印を押すときです。次に、この全画面で回転して「完了」を押すと、画面は元の向きに維持されます。 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

関連する問題