【问题标题】:Flickering UIView in simulator using Playground使用 Playground 在模拟器中闪烁 UIView
【发布时间】:2015-08-13 09:46:23
【问题描述】:

我正在运行 Xcode 6.4,玩游乐场,我编写了这个超级基础代码。

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

import UIKit
import XCPlayground

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

XCPShowView("View", eenView)

模拟器正在显示,视图也在显示,但是……它在闪烁!!

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

【问题讨论】:

    标签: ios swift uiview swift-playground


    【解决方案1】:

    更新

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-20
      • 2019-12-01
      • 1970-01-01
      • 2022-10-20
      • 2012-10-07
      • 2023-03-30
      相关资源
      最近更新 更多