Ios iPhone屏幕方向与';cordova 3.5.0中的t变化
当我使用iPhone在我的应用程序中旋转屏幕时,屏幕始终保持纵向,没有任何变化。不过,它在iPad上运行良好。我可以旋转它并改变方向 当我打开iPhone时,如何让我的应用程序改变屏幕方向 在config.xml中,我有:Ios iPhone屏幕方向与';cordova 3.5.0中的t变化,ios,iphone,cordova,screen-orientation,Ios,Iphone,Cordova,Screen Orientation,当我使用iPhone在我的应用程序中旋转屏幕时,屏幕始终保持纵向,没有任何变化。不过,它在iPad上运行良好。我可以旋转它并改变方向 当我打开iPhone时,如何让我的应用程序改变屏幕方向 在config.xml中,我有: <preference name="Orientation" value="default" /> 但对我来说,这似乎是一个丑陋的解决方案,我真的很想找到正常的方法来做这件事 理想情况下,iPad和iPhone的所有方向都是从上到下的,但我不知道是否允许我做梦
<preference name="Orientation" value="default" />
但对我来说,这似乎是一个丑陋的解决方案,我真的很想找到正常的方法来做这件事
理想情况下,iPad和iPhone的所有方向都是从上到下的,但我不知道是否允许我做梦
还有其他人对iPhone和cordova有类似的问题吗?我已经在谷歌上搜索了好几天,除了科尔多瓦代码中的这一黑客行为外,我什么也找不到。在广泛搜索解决方案后,我不幸得出结论,这是科尔多瓦的问题。
<preference name="Orientation" value="default" />
代码应实际更改iOS配置文件(/platform/iOS/~app\u name~/~app\u name~.plist)中的平台UISupportedInterfaceOrientations键,以包含以下值:
- “UIInterfaceOrientationAndscapeLeft”李>
- “UIInterfaceOrientationAndscapeRight”李>
- “UIInterfaceOrientationPortrait”;(我想)
- “UIInterfaceOrientationGraphicalUpsideDown”
希望这有帮助。如果有更好的解决方案或Cordova解决此疏忽,请让我知道 我从这里创建了一个钩子文件:
#/usr/bin/env节点
var fs=需要('fs');
var plist='platforms/ios/-Info.plist';
var iphoneModes=[
“UIInterfaceOrientationAndscapeLeft”,
“UIInterfaceOrientationAndscapeRight”,
“UIInterfaceOrientationPortrait”
];
变量ipadModes=[
“UIInterfaceOrientationAndscapeLeft”,
“UIInterfaceOrientationAndscapeRight”
];
函数getOrientationModeStr(模式){
var s=“$1\n\t\n\t”;
模式。forEach(函数(模式,索引){
s+=“\t”+模式+“\n\t”;
});
返回s;
}
if(fs.existsSync(plist)){
var p=fs.readFileSync(plist,'utf8');
//取代iphone模式
p=p.替换(
/(UI支持接口方向)[\r\n]*[\s\s]*?(?=)/ig,
GetOrientionModestr(iphoneModes)
);
//取代ipad模式
p=p.替换(
/(UISupportedInterfaceOrientations~ipad)[\r\n]*[\s\s]*?(?=)/ig,
getOrientationModeStr(ipadModes)
);
fs.writeFileSync(plist,p,“utf8”);
}
希望它能有所帮助。我在XCode中创建了一个使用PListBuddy的构建阶段,这样无论何时运行
cordova构建ios
,它都会运行构建阶段并更新PList文件。这样做的好处是,如果更改config.xml并更改PList,则构建阶段会介入并确保值存在
我从这里被接受的答案中得到了这个想法:
作为旁注,我们不应该为了吃蛋糕而跳槽,但无论如何。作为旁注,记下其他config.xml选项不起作用的地方是值得的。请张贴,如果有其他人,以避免浪费更多的时间…我不喜欢修改科尔多瓦生成的代码。这里有一个Javascript解决方案。这里有一个Javascript解决方案:这真的很酷,谢谢。我做了一些恼人的字符串替换来尽可能地自动化我的构建,但这样做效果更好
<preference name="Orientation" value="default" />
#!/usr/bin/env node
var fs = require('fs');
var plist = 'platforms/ios/<app-name>/<app-name>-Info.plist';
var iphoneModes = [
"UIInterfaceOrientationLandscapeLeft",
"UIInterfaceOrientationLandscapeRight",
"UIInterfaceOrientationPortrait"
];
var ipadModes = [
"UIInterfaceOrientationLandscapeLeft",
"UIInterfaceOrientationLandscapeRight"
];
function getOrientationModeStr(modes) {
var s = "<key>$1</key>\n\t<array>\n\t";
modes.forEach(function(mode, index) {
s += "\t<string>"+mode+"</string>\n\t";
});
return s;
}
if (fs.existsSync(plist)) {
var p = fs.readFileSync(plist, 'utf8');
// replace iphone modes
p = p.replace(
/<key>(UISupportedInterfaceOrientations)<\/key>[\r\n ]*<array>[\s\S]*?(?=<\/array>)/ig,
getOrientationModeStr(iphoneModes)
);
// replace ipad modes
p = p.replace(
/<key>(UISupportedInterfaceOrientations~ipad)<\/key>[\r\n ]*<array>[\s\S]*?(?=<\/array>)/ig,
getOrientationModeStr(ipadModes)
);
fs.writeFileSync(plist, p, "utf8");
}
#Grabs info from plist
plist=$SRCROOT"/"$INFOPLIST_FILE
orientations=`/usr/libexec/PlistBuddy -c "Print :UISupportedInterfaceOrientations" "$plist"`
#And changes it before writing out the plist again
if [ "$orientations" ]
then
/usr/libexec/PlistBuddy -c "Delete :UISupportedInterfaceOrientations array" "$plist"
fi
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations array" "$plist"
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations:0 string \"UIInterfaceOrientationPortrait\"" "$plist"
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations:0 string \"UIInterfaceOrientationPortraitUpsideDown\"" "$plist"
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations:0 string \"UIInterfaceOrientationLandscapeLeft\"" "$plist"
/usr/libexec/PlistBuddy -c "Add :UISupportedInterfaceOrientations:0 string \"UIInterfaceOrientationLandscapeRight\"" "$plist"