【发布时间】:2015-06-05 21:58:54
【问题描述】:
我使用此代码弹出一个随机图像:
@IBOutlet weak var imageView: UIImageView!
@IBAction func startButton(sender: AnyObject) {
UIView.animateWithDuration(0.5, delay:2, options:UIViewAnimationOptions.TransitionFlipFromTop, animations: {
self.imageView.alpha = 2
}, completion: { finished in
self.imageView.image = UIImage(named: "gameBall\(arc4random_uniform(12) + 1).png")
})
}
当用户向下滑动时,我想检测图像的名称,然后如果向下滑动正确的图像,我希望它说“1 点!”如果向下滑动错误的图像,我希望它说“游戏结束!”我已经有一些代码不起作用,因为它只显示“游戏结束!”我在哪里刷卡:
func respondToSwipeGesture(sender: UISwipeGestureRecognizer) {
switch sender.direction {
case UISwipeGestureRecognizerDirection.Down:
if imageView == UIImage(named: "gameBall2.png"){
println("1 point!")
}else{
println("Game Over!")
}
default:
break
}
}
override func viewDidLoad() {
super.viewDidLoad()
var swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.view.addGestureRecognizer(swipeRight)
var swipeDown = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeDown.direction = UISwipeGestureRecognizerDirection.Down
self.view.addGestureRecognizer(swipeDown)
self.view.userInteractionEnabled = true
【问题讨论】:
-
比较
UIImageView和UIImage永远不会成功。 -
那么就没有办法了吗?
-
您可以尝试将图像视图的图像与
UIImage进行比较。 -
图像视图的图像?
-
不,没有用 :(
标签: ios swift uiimage uiswipegesturerecognizer