我试图编写一个包含两个图像的程序。我使用4个按钮上,下,左,右移动一个图像。 如果该图像到达另一个图像,文本字段将显示:“您是赢家!”。Swift中的“预期声明”
但是,包含代码If ...的行始终得到“Expected Declaration”错误。我如何让它运行,请问?
这是整个代码,两个图像的名称ConChimCu和忠:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var txtBai: UITextView!
@IBOutlet weak var ConChimCu: UIImageView!
@IBOutlet weak var Trung: UIImageView!
@IBAction func Up(sender: AnyObject) {
ConChimCu.frame.origin.y = ConChimCu.frame.origin.y - 2
}
@IBAction func RIGHT(sender: AnyObject) {
ConChimCu.frame.origin.x = ConChimCu.frame.origin.x + 2
}
@IBAction func DOWN(sender: AnyObject) {
ConChimCu.frame.origin.y = ConChimCu.frame.origin.y + 2
}
@IBAction func LEFT(sender: AnyObject) {
ConChimCu.frame.origin.x = ConChimCu.frame.origin.x - 2
}
if ConChimCu.frame.origin.x == Trung.frame.origin.x { txtBai.text = "You are the winner!"
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
[预期宣言错误的可能的复制的Xcode 6.2使用夫特(http://stackoverflow.com/questions/29835490/expected-declaration-error-xcode-6-2-使用迅速) – vadian