2

私はページに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;
}

ビューは、ポートレートでもランドスケープでも正常に機能しています。問題は、フルスクリーンでビデオを見て回転したときです。全画面表示を終了すると、Webビューが回転を検出せず、Webビューを間違った方法で印刷しました。

ビューを回転させるためにYoutubeの全画面が回転していることをどのように検出できますか?

ありがとうございました

4

3 に答える 3

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>

...。

于 2011-12-13T17:14:54.090 に答える
-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
于 2011-11-14T22:00:07.927 に答える
-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];
    }
}

お役に立てば幸いです

于 2012-05-02T06:52:35.243 に答える