UIToolbar偏移 - 出现黑条

时间:2015-02-08 17:46:02

标签: ios swift interface-builder

所以这是我的Swift代码(AppDelegate.swift):

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
}

我试图将屏幕缩小20px。

这是我的模拟器使用上面的代码看起来的样子(错误!):

enter image description here

如果我什么都不做的话,这就是它的样子(错误!):

enter image description here

这就是我想要它的样子!

enter image description here

我一直都在这个小时候。

我想要一种强大且易于管理的方式将所有内容降低20px。

(p.s。我使用故事板)

1 个答案:

答案 0 :(得分: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()
相关问题