Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin 如何使用iOS 8 SDK重新缩放PlayN应用程序?_Xamarin_Ios8_Playn - Fatal编程技术网

Xamarin 如何使用iOS 8 SDK重新缩放PlayN应用程序?

Xamarin 如何使用iOS 8 SDK重新缩放PlayN应用程序?,xamarin,ios8,playn,Xamarin,Ios8,Playn,这个问题的背景是iOS 8、Xamarin和PlayN,其应用程序仅处于横向模式 我曾经基于UIScreen.MainScreen.Bounds在FinishedLaunching中重新缩放我的应用程序,以适应不同的屏幕大小。随着iOS 8 SDK的出现,API的语义发生了变化。以前,UIScreen与方向无关。下面是以前的SDK的代码,以前的SDK工作正常: public partial class AppDelegate : UIApplicationDelegate { publi

这个问题的背景是iOS 8、Xamarin和PlayN,其应用程序仅处于横向模式

我曾经基于
UIScreen.MainScreen.Bounds
FinishedLaunching
中重新缩放我的应用程序,以适应不同的屏幕大小。随着iOS 8 SDK的出现,API的语义发生了变化。以前,
UIScreen
与方向无关。下面是以前的SDK的代码,以前的SDK工作正常:

public partial class AppDelegate : UIApplicationDelegate
{
    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        app.SetStatusBarStyle (UIStatusBarStyle.LightContent, false);

        IOSPlatform.Config config = new IOSPlatform.Config ();
        config.orients = IOSPlatform.SupportedOrients.LANDSCAPES;
        IOSPlatform.register (app, config);

        System.Drawing.RectangleF bounds = UIScreen.MainScreen.Bounds;

        // Flip width and height when in landscape for iOS SDK before iOS 8
        float screenHeight = bounds.Width; 
        float screenWidth  = bounds.Height;

        float heightRatio = screenHeight / MyGame.HEIGHT;
        float widthRatio  = screenWidth / MyGame.WIDTH;

        float ratio = (heightRatio < widthRatio ? heightRatio : widthRatio);
        PlayN.graphics ().rootLayer ().setScale (ratio, ratio);
        MyGame game = new MyGame ();
        PlayN.run (game);
        return true;
    }
}
公共部分类AppDelegate:UIApplicationDelegate
{
公共覆盖bool FinishedLaunching(UIApplication应用程序、NSDictionary选项)
{
app.SetStatusBarStyle(UIStatusBarStyle.LightContent,false);
iossplatform.Config=newiossplatform.Config();
config.orients=iossplatform.SupportedOrients.LANDSCAPES;
iossplatform.register(应用程序,配置);
System.Drawing.RectangleF bounds=UIScreen.MainScreen.bounds;
//在iOS 8之前的iOS SDK中处于横向时翻转宽度和高度
浮动屏幕高度=边界宽度;
浮动屏幕宽度=边界高度;
浮动高度比率=屏幕高度/MyGame.HEIGHT;
浮动宽度比率=屏幕宽度/MyGame.WIDTH;
浮动比率=(高度比率<宽度比率?高度比率:宽度比率);
PlayN.graphics().rootLayer().setScale(比率、比率);
MyGame=newmygame();
跑(游戏);
返回true;
}
}
在iOS 8 SDK中,
UIScreen
现在是面向接口的。我认为只要删除上面的代码翻转高度和宽度就足以迁移。但事实并非如此。用户界面向右移动大约三分之一的屏幕,并且失真

背景:

  • Xcode 6 beta 6
  • Xamarin.iOS 7.9.4.29
  • 1.8.5

任何迁移此代码的建议都将不胜感激。

以下是对我有效的建议:

public UIWindow window;
在渔场

window = new UIWindow(mainViewController.View.Bounds);

解决方案是迁移到PlayN 1.9 alpha 1,它现在基于RoboVM而不是Xamarin

在Info.plist.xml中:

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationLandscapeLeft</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationLandscapeLeft</string>
</array>
UI支持接口方向
UIInterface方向和左视图
UI支持界面方向~ipad
UIInterface方向和左视图
以及启动游戏的java代码(不再需要C#)

公共类MetroRoboVM扩展UIApplicationLegateApter{
@凌驾
公共布尔DidFinishLaunch(UIApplicationApp、UIApplicationLaunchOptions launchOpts){
app.setStatusBarStyle(UIStatusBarStyle.LightContent,false);
RoboPlatform.Config Config=新的RoboPlatform.Config();
config.orients=UIInterfaceOrientationMask.LandscapeLeft;
机器人平台=机器人平台。注册(应用程序,配置);
addStrongRef(平台);
字符串systemVersion=UIDevice.getCurrentDevice().getSystemVersion();
int indexPoint=systemVersion.indexOf(“.”);
如果(indexPoint>0){
systemVersion=systemVersion.substring(0,indexPoint);
}
int majorVersionNumber=Integer.parseInt(系统版本);
布尔isIOS8=主版本号>=8;
CGSize bounds=UIScreen.getMainScreen().getBounds().size();
double screenHeight=isIOS8?bounds.height():bounds.width();
double screenWidth=isIOS8?bounds.width():bounds.height();
双倍高度比=屏幕高度/MyGame.HEIGHT;
双宽度比=屏幕宽度/MyGame.WIDTH;
双比值=(高比值<宽比值?高比值:宽比值);
PlayN.graphics().rootLayer().setScale((浮动)比率,(浮动)比率);
platform.run(新的MyGame());
返回true;
}
...
}

有什么解决方案吗?我遇到了同样的问题!为什么苹果不能生产出能持续工作的产品?每次发布都会让我做噩梦。。。谢谢,RickI在谷歌开发者论坛上问道。PlayN开发者承认他们有一个严重的问题:从那时起我就在等待补丁。
public class MetroRoboVM extends UIApplicationDelegateAdapter {

  @Override
  public boolean didFinishLaunching (UIApplication app, UIApplicationLaunchOptions launchOpts) {
    app.setStatusBarStyle (UIStatusBarStyle.LightContent, false);

    RoboPlatform.Config config = new RoboPlatform.Config ();
    config.orients = UIInterfaceOrientationMask.LandscapeLeft; 
    RoboPlatform platform = RoboPlatform.register(app, config);
    addStrongRef(platform);

    String systemVersion = UIDevice.getCurrentDevice().getSystemVersion();
    int indexPoint = systemVersion.indexOf(".");
    if (indexPoint > 0) {
      systemVersion = systemVersion.substring(0,indexPoint);
    }
    int majorVersionNumber = Integer.parseInt(systemVersion);
    boolean isIOS8 = majorVersionNumber >= 8;
    CGSize bounds = UIScreen.getMainScreen().getBounds().size();

    double screenHeight = isIOS8 ? bounds.height() : bounds.width(); 
    double screenWidth  = isIOS8 ? bounds.width()  : bounds.height();

    double heightRatio = screenHeight / MyGame.HEIGHT;
    double widthRatio =  screenWidth / MyGame.WIDTH;
    double ratio = (heightRatio < widthRatio ? heightRatio : widthRatio);
    PlayN.graphics().rootLayer().setScale ((float)ratio, (float)ratio);

    platform.run(new MyGame());
    return true;
 }
...
}