我是学习Swift的新手,我正试图让一个非常简单的应用程序运行.我想要做的就是在按下按钮时让UIView.drawRect更新.它会在应用程序首次加载时更新/绘制,然后在我尝试之后无需更新/绘制.几天来,我一直在反对这一点,我找不到任何帮助.
我建立:
单一视图应用程序
一个按钮,链接到视图控制器作为动作
一个新类,Test_View,子类化UIView
ViewController代码:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var f = Test_View()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Button_Pressed(sender: AnyObject) {
var f = Test_View()
f.setNeedsDisplay()
NSLog("Button pressed.")
}
}
Run Code Online (Sandbox Code Playgroud)
Test_View代码:
class Test_View: UIView {
override func drawRect(rect: CGRect) {
let h = rect.height
let w …
Run Code Online (Sandbox Code Playgroud)