我正在尝试在 UIWebView 中播放 YouTube 视频(参见下面的代码)。
一切正常,但 YouTube 播放器不支持 iOS 6 上的方向更改。我的整个应用仅处于纵向模式。
我该如何解决这个问题?任何帮助表示赞赏。
我使用的代码如下:
- (void)viewDidLoad
{
[super viewDidLoad];
float width = 300.0f;
float height = 300.0f;
youTubeURL = @"http://www.youtube.com/embed/ZiIcqZoQQwg";
UIWebView *wv = [[UIWebView alloc] init];
wv.frame = CGRectMake(10, 80, width, height);
NSMutableString *html = [[NSMutableString alloc] initWithCapacity:1] ;
[html appendString:@"<html><head>"];
[html appendString:@"<style type=\"text/css\">"];
[html appendString:@"body {"];
[html appendString:@"background-color: black;"];
[html appendString:@"color: white;"];
[html appendString:@"}"];
[html appendString:@"</style>"];
[html appendString:@"</head><body style=\"margin:0\">"];
[html appendFormat:@"<embed id=\"yt\" src=\"%@\"", youTubeURL];
[html appendFormat:@"width=\"%0.0f\" height=\"%0.0f\"></embed>", 300.0f, 300.0f];
[html appendString:@"</body></html>"];
[wv loadHTMLString:html baseURL:nil];
[self.view addSubview:wv];
}
最佳答案
您需要做的如下...
首先在 viewdidLoad 中发出一个通知,当您旋转设备时将调用该通知..
-(void)ViewDidLoad
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(rotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
现在通知将调用名为“rotate:”的方法,因此我们必须像下面那样实现该方法。
#pragma mark - Rotate Screen Method
- (void)rotate:(NSNotification *)n {
switch ([[UIDevice currentDevice] orientation]) {
case UIDeviceOrientationLandscapeLeft:
yourwebview.transform = CGAffineTransformMakeRotation(M_PI / 2);
yourwebview.frame = CGRectMake(0, 0, 768, 1024);//you can set any frame
break;
case UIDeviceOrientationLandscapeRight:
yourwebview.transform = CGAffineTransformMakeRotation(-M_PI / 2);
yourwebview.frame = CGRectMake(0, 0,768, 1024);//you can set any frame
break;
case UIDeviceOrientationPortrait:
yourwebview.transform = CGAffineTransformIdentity;
yourwebview.frame = CGRectMake(0, 0, 768, 1024);//you can set any frame
break;
case UIDeviceOrientationPortraitUpsideDown:
yourwebview.transform = CGAffineTransformMakeRotation(M_PI);
yourwebview.frame = CGRectMake(0, 0, 768, 1024);//you can set any frame
break;
default:
break;
}
}
就是这样。
关于iphone - iOS 6 上的 YouTube 播放器方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16955116/
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
我有一个.pfx格式的证书,我需要使用ruby提取公共(public)、私有(private)和CA证书。使用shell我可以这样做:#ExtractPublicKey(askforpassword)opensslpkcs12-infile.pfx-outfile_public.pem-clcerts-nokeys#ExtractCertificateAuthorityKey(askforpassword)opensslpkcs12-infile.pfx-outfile_ca.pem-cacerts-nokeys#ExtractPrivateKey(askforpassword)o
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
我了解instance_eval和class_eval之间的基本区别。我在玩弄时发现的是一些涉及attr_accessor的奇怪东西。这是一个例子:A=Class.newA.class_eval{attr_accessor:x}a=A.newa.x="x"a.x=>"x"#...expectedA.instance_eval{attr_accessor:y}A.y="y"=>NoMethodError:undefinedmethod`y='forA:Classa.y="y"=>"y"#WHATTT?这是怎么回事:instance_eval没有访问我们的A类(对象)然后它实际上将它添加到
我有一个集合选择:此方法的单选按钮是什么?谢谢 最佳答案 Rails3中没有这样的助手。在Rails4中,它是collection_radio_buttons. 关于ruby-on-rails-rails上的ruby:radiobuttonsforcollectionselect,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/18525986/