2013-05-03 52 views
0

我正在製作一個加載了YouTube視頻的iPad應用程序。我能夠通過在線發現一些iframe代碼來獲得UIWebView以加載YouTube視頻。我需要能夠旋轉iPad,並且在旋轉到橫向時不會裁剪視頻,但同時橫向和縱向寬度均爲設備的整個寬度。我在iframe中放置了什麼?我試過用通過uiwebview在iframe中指定的尺寸在旋轉到橫向時指定尺寸不切斷

"meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no" 

但它沒有工作。 。?我試圖把它在iframe腳本(不能不之間的範圍內這不可能是正確的任何想法,任何幫助是極大的讚賞這裏是我下面的代碼:

.M

#import "ViewController.h" 
#import <AVFoundation/AVFoundation.h> 

@interface ViewController() 

@end 

@implementation ViewController 

@synthesize webView; 

-(void)viewDidLoad 
{ 

    [super viewDidLoad]; 
    [self embedYouTube]; 

    NSLog(@"frame:%@", NSStringFromCGRect(self.view.frame)); // prints frame:{{0, 0}, {768, 1004}} 
    NSLog(@"bounds:%@", NSStringFromCGRect([[self view] bounds])); // prints frame:{{0, 0}, {768, 1004}} 

} 

-(void)embedYouTube{ 

    AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
    BOOL ok; 
    NSError *setCategoryError = nil; 
    ok = [audioSession setCategory:AVAudioSessionCategoryPlayback 
         error:&setCategoryError]; 
    if (!ok) { 
     NSLog(@"%s setCategoryError=%@", __PRETTY_FUNCTION__, setCategoryError); 
} 


    NSString *embedHTML = @"<iframe height=\"700\" width=\"900\" src=\"http://www.youtube.com/embed/QK8mJJJvaes\" frameborder=\"0\" allowfullscreen></iframe>"; 


    NSString *html = [NSString stringWithFormat:embedHTML]; 

    [webView loadHTMLString:html baseURL:nil]; 
    [self.view addSubview:webView]; 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

在我AppDelegate.m文件,我有:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// we support rotation in this view controller 
return YES; 
} 

的.xib

視圖和web視圖具有自動調整子視圖檢查,定向的觀點是肖像,尺寸的看法是沒有,都是模式中心nd webView縮放以適合頁面。

回答

1

我最終弄清楚了給Xcode一個長寬比計算器的確切尺寸。

-(void)embedYouTube{ 

    AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
    BOOL ok; 
    NSError *setCategoryError = nil; 
    ok = [audioSession setCategory:AVAudioSessionCategoryPlayback 
        error:&setCategoryError]; 
    if (!ok) { 
    NSLog(@"%s setCategoryError=%@", __PRETTY_FUNCTION__, setCategoryError); 
    } 

    NSString *embedHTML = @"<iframe height=\"548\" width=\"975\" src=\"http://www.youtube.com/embed/QK8mJJJvaes\" frameborder=\"0\" allowfullscreen></iframe>"; 

    NSString *html = [NSString stringWithFormat:embedHTML]; 

    [webView loadHTMLString:html baseURL:nil]; 
    [self.view addSubview:webView]; 

}