2014-09-05 149 views
0

這個問題的上下文是iOS 8,僅適用於橫向模式的Xamarin和PlayN。如何使用iOS 8 SDK重新調整PlayN應用程序?

我曾經根據UIScreen.MainScreen.BoundsFinishedLaunching中的應用進行了重新調整,以適應不同的屏幕尺寸。使用iOS 8 SDK時,API的語義發生了變化。以前,UIScreen不取決於方向。這裏以前的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; 
    } 
} 

與iOS 8 SDK,UIScreen現面向接口。我認爲只是刪除翻轉高度和寬度的代碼將足以遷移。但這種情況並非如此。用戶界面向右移動大約三分之一的屏幕並失真。

上下文:

  • 的Xcode 6的β6個
  • Xamarin.iOS 7.9.4.29
  • 1.8.5

任何意見遷移這個代碼將不勝感激。

+0

任何解決方案?我遇到了同樣的問題!蘋果爲什麼不讓這些工作繼續下去?每個版本都會導致我的噩夢... 謝謝, Rick – Rick 2014-10-28 17:45:47

+0

我在谷歌開發者論壇上問過。 PlayN開發人員承認他們有一個嚴重的問題:[看到這裏](https://groups.google.com/forum/#!topic/playn/rAmw43lVGak)從那以後,我正在等待補丁。 – fredstroup 2014-10-30 08:28:40

回答

1

的解決方案是遷移到PlayN 1.9阿爾法1這是目前基於RoboVM而不是Xamarin。

在Info.plist.xml:

<key>UISupportedInterfaceOrientations</key> 
<array> 
    <string>UIInterfaceOrientationLandscapeLeft</string> 
</array> 
<key>UISupportedInterfaceOrientations~ipad</key> 
<array> 
    <string>UIInterfaceOrientationLandscapeLeft</string> 
</array> 

和Java代碼啓動遊戲(無需C#了)

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; 
} 
... 
} 
0

下面是我工作:

public UIWindow window; 

在FishedLaunchine

window = new UIWindow(mainViewController.View.Bounds); 
相關問題