0

我正在制作一个加载 youtube 视频的 iPad 应用程序。我能够获得一个 UIWebView 来加载一个带有一些在线找到的 iframe 代码的 youtube 视频。我需要能够旋转 iPad,并且在旋转到横向时不会裁剪视频,但同时横向和纵向宽度都是设备的全宽。我在 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

视图和 webView 都选中了 Autoresize 子视图,视图方向为纵向,视图大小为无,两者都是模式中心和 webView 缩放以适应页面。

4

1 回答 1

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];

}
于 2013-05-06T04:53:29.420 回答