【发布时间】:2015-04-19 12:54:46
【问题描述】:
我正在尝试设置一个手势识别器 (UITapGestureRecognizer),它通过单击一次并将视图颜色更改为蓝色并在第二次单击将其更改为黄色然后返回默认颜色红色来工作。
class ViewController: UIViewController {
var squarView:UIView!;
var squarIsBlue:Bool = true;
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
squarView = UIView(frame: CGRect(x: 130, y: 130, width: 150, height: 150));
squarView.backgroundColor = UIColor.redColor();
var squarTap = UITapGestureRecognizer(target: self, action: "tapMe:");
squarView.addGestureRecognizer(squarTap);
squarView.userInteractionEnabled = true;
view.addSubview(squarView);
}
func tapMe(sender:UIGestureRecognizer){
squarView.backgroundColor = UIColor.blueColor();
if (squarIsBlue == false){
squarView.backgroundColor = UIColor.yellowColor();
if(squarIsBlue == true){
squarView.backgroundColor = UIColor.redColor();
}
squarIsBlue = true
}
squarIsBlue = false;
println("Squar Tapped!!!");
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我做错了什么?
【问题讨论】:
标签: ios swift view uiview uitapgesturerecognizer