2015-02-08 32 views
1

因此,這裏是我的電匯代碼(AppDelegate.swift):UIToolbar偏移 - 出現黑條

var window: UIWindow? 
var rootViewController :UIViewController? 

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 

    if ((UIDevice.currentDevice().systemVersion as NSString).floatValue >= 7) { 
     //yes, I'm using a newer iOS - greater/equal to iOS 7 
     rootViewController = Login(nibName:"Login",bundle:nil) 
     let x = UIScreen.mainScreen().bounds.size.width 
     let y = UIScreen.mainScreen().bounds.size.height 
     let frame = CGRectMake(0,20,x,y) 
     window = UIWindow(frame: frame) 

     window!.rootViewController = rootViewController 
     window!.makeKeyAndVisible()     

     //window!.frame = CGRectMake(0,20,window!.frame.size.width,window!.frame.size.height-20); 
    } 

    return true 
} 

我想下跌20像素偏置的畫面。

這裏就是我的仿真器看起來像使用上面的代碼(錯誤!):

enter image description here

這裏是什麼樣子,如果我什麼都不做(錯了!):

enter image description here

這就是我想要的樣子!

enter image description here

我已經在這幾個小時。

我想要一個強大且易於管理的方式將所有內容都向下移動20px。

(附註:我不使用故事板)

回答

0

這似乎工作:

 rootViewController = Login(nibName:"Login",bundle:nil) 

     if ((UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8) { 
      //For iOS 8 
      rootViewController?.providesPresentationContextTransitionStyle = true 
      rootViewController?.definesPresentationContext = true; 
      rootViewController?.modalPresentationStyle = UIModalPresentationStyle.CurrentContext 
     }else{ 
      //For iOS 7 
      rootViewController?.modalPresentationStyle = UIModalPresentationStyle.CurrentContext 
     } 
     let x = UIScreen.mainScreen().bounds.size.width 
     let y = UIScreen.mainScreen().bounds.size.height 
     let frame = CGRectMake(0, 0, x, y) 
     window = UIWindow(frame: frame) 
     window!.rootViewController = rootViewController 
     window!.makeKeyAndVisible()