我正在制作一款加载YouTube视频的iPad应用。我能够获得一个UIWebView来加载youtube视频,其中包含一些在线找到的iframe代码。我需要能够旋转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子视图,视图方向为纵向,视图大小为none,模式中心和webView缩放以适合页面。
答案 0 :(得分: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];
}