使用 Playground 在模拟器中闪烁 UIView

Flickering UIView in simulator using Playground

我运行宁Xcode6.4,玩playground,我写的这个超级基础的代码

我想 运行 模拟器中的代码,所以我打开了实用程序选项卡 (alt-cmd-0) 并选择支票簿“ [v] 运行 in Full Simulator”

import UIKit
import XCPlayground

let eenView = UIView(frame: CGRectMake(0, 0, 100, 100))
eenView.backgroundColor = UIColor.orangeColor()

XCPShowView("View", eenView)

正在显示模拟器和视图,但是...闪烁!!

(我已经尝试了很多东西,比如重置所有模拟器,创建新的模拟器,似乎没有任何效果,我想知道我是否需要在我的代码中添加一些东西)

更新

import UIKit

//setup

struct MainScene {
    let vc: UIViewController
    let nc: UINavigationController
    init(vc: UIViewController) {
        self.vc = vc
        self.nc = UINavigationController(rootViewController: vc)
    }
}

extension UIViewController {
    class func viewController(color: UIColor) -> UIViewController {
        let vc = UIViewController()
        vc.view = UIView(frame: UIScreen.mainScreen().bounds)
        vc.view.backgroundColor = color
        return vc
    }
}

let vc = UIViewController.viewController(UIColor.lightGrayColor())
vc.title = "title"

////////Write your prototype code there

////////End of your prototype

let mainScene = MainScene(vc: vc)

//Run playground
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
window.rootViewController = mainScene.nc
window.makeKeyAndVisible()
CFRunLoopRun()

这就是解决方案,如果有人感兴趣...

我修改了ilyapuchka的代码(他实现了很好的例子):

https://gist.github.com/ilyapuchka/1ae19259161a91f3a8a8