2011-05-15 49 views
0

我提出這樣一個UIWebView(情況2):UIWebView的交換機不改變方向爲橫向

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    CGRect frame = CGRectMake(0, 0, 320, 400); 
    SongDetailsTVC *infoVC; 
    UIWebView *ytView; 
    NSString *htmlVideoHTML, *html; 
    UIViewController *youtubeController; 
    switch (buttonIndex) { 
     case 0: 
      [self swapLanguage]; 
      break; 
     case 1: 
      infoVC = [[SongDetailsTVC alloc] initWithStyle:UITableViewStyleGrouped]; 
      [infoVC setSongData:songData]; 
      [infoVC setTitle:@"Song Info"]; 
      [[self navigationController] pushViewController:infoVC animated:YES]; 
      [infoVC release]; 
      break; 
     case 2: 

      // HTML to embed YouTube video 
      htmlVideoHTML = @"<html><head>\ 
      <body style=\"margin:0\">\ 
      <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ 
      width=\"%0.0f\" height=\"%0.0f\"></embed>\ 
      </body></html>"; 

      // Populate HTML with the URL and requested frame size 
      html = [NSString stringWithFormat:htmlVideoHTML, [songData objectForKey:@"YouTube Link (Value)"], frame.size.width, frame.size.height]; 

      // Load the html into the webview       
      ytView = [[UIWebView alloc] initWithFrame:frame]; 
      [ytView setMediaPlaybackRequiresUserAction:NO]; 
      [ytView loadHTMLString:html baseURL:nil]; 

      youtubeController = [[UIViewController alloc] init]; 
      [youtubeController setView:ytView]; 
      [youtubeController setTitle:@"YouTube Video"]; 
      [[self navigationController] pushViewController:youtubeController animated:YES]; 

      [ytView release]; 
      [youtubeController release]; 

      break; 
     default: 
      break; 
    } 
} 

的問題是,當我切換到橫向模式,它不會改變其方向。我究竟做錯了什麼?謝謝。

回答

2

旋轉由視圖控制器決定,而不是視圖。 UIViewController的shouldAutorotateToInterfaceOrientation:的默認實現僅對肖像返回YES;您將不得不創建UIViewController的子類,重寫該方法,並使用該子類代替庫存UIViewController。

0

UIWebView有一個非常天真的方法,從例如, CSS3媒體查詢。

基本上,如果它比它高,它被認爲是風景,如果它比它更寬,它被認爲是肖像。由於您的網頁瀏覽量固定爲320 x 400,它將始終返回肖像。

相關問題