我正在运行一个操场,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)