在从操场上运行的模拟器中闪烁的UIView

时间:2015-03-17 21:41:43

标签: xcode swift swift-playground xcplayground

我正在操场,Xcode 6.3(6D543q)。因此Swift 1.2

Playground导入XCPlayground。 我正在创建一个UIView并调用XCPShowView()让它在模拟器中而不是在Playground中呈现。 我也以同样的方式呈现UIAlertView。

UIAlertView正常显示。 UIView在较大和较小的尺寸之间闪烁大约每秒5次,合理的不规则。 我已经尝试过调整它以满足屏幕的界限,但没有运气。

以下代码......

// Playground - noun: a place where people can play

import UIKit
import Foundation
import XCPlayground

 XCPlayground.XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)

@objc class alertHandler: NSObject, UIAlertViewDelegate {

  func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
    if buttonIndex > 0 {

     // View things....
     let redRectangleFrame = CGRect(x: 0, y: 0, width: 200, height: 200)
     let redRectangle = UIView(frame: redRectangleFrame)
     redRectangle.backgroundColor = UIColor.redColor()
     redRectangle.setTranslatesAutoresizingMaskIntoConstraints(false)
     XCPShowView("Red Rectangle", redRectangle)

     // Alert view things...
     let recevingAlertView = alertView

     let text = alertView.textFieldAtIndex(0)?.text
     println("\(text!)")
     println("Button \(buttonIndex)")
    }
  }
}

let anAlertHandler = alertHandler()

let status = "Hey there!"
let message = "Do you have a moment to talk about our Lord and Saviour, Cthulhu?"
let cancel = "Sounds wierd"
let ok = "Oooh! Yes"

let alert = UIAlertView(title: status,
                  message: message,
                 delegate: anAlertHandler,
        cancelButtonTitle: cancel,
        otherButtonTitles: ok)
alert.alertViewStyle = UIAlertViewStyle.PlainTextInput
alert.show()

XCPShowView("Alert", alert)

1 个答案:

答案 0 :(得分:1)

Noticed some flicker locally with a few test playground simulator examples (your example was crashing for me Version 6.3.2 (6D2105))

From this post (their animation did show up but was flickering, and overlapping)

There are some limitations and draw backs to UIKit in Playgrounds. The primary limitation is that Auto Layout has some issues when used in Playgrounds. Some constraints will cause runtime exceptions in addition to increased compile times. Hopefully future updates to Xcode will resolve this. Another draw back is the performance of Playgrounds when using XCPlayground. There can be delays as Xcode works with the iOS Simulator running behind the Playground.