您好我打了一堵砖墙,我一直在为我的应用重新设计菜单导航。我设法做到了。但现在我的应用程序的一个功能已决定停止运行。
这个想法是你摇动你的手机并随机选择一张图片,与应用程序分开的代码工作得很好,正如它在以前版本的所有版本上所做的那样,我甚至快速运行它的现有形式就可以了拥有以防万一,它完美无缺。
希望有人可以指出我出错的方向。
我的代码如下;
import Foundation
import UIKit
class cocktailChoice: UIViewController {
@IBOutlet weak var drinkImage: UIImageView!
var drinkNamesArray:[String] = ["cocktailList0","cocktailList1","cocktailList2","cocktailList3","cocktailList4","cocktailList5","cocktailList6","cocktailList7","cocktailList8","cocktailList9","cocktailList10","cocktailList11","cocktailList12","cocktailList13","cocktailList14","cocktailList15","cocktailList16","cocktailList17","cocktailList18","cocktailList19","cocktailList20","cocktailList21","cocktailList22","cocktailList23","cocktailList24","cocktailList25","cocktailList26","cocktailList27","cocktailList28","cocktailList29","cocktailList30","cocktailList31"]
override func viewDidLoad() {
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
override func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) {
if motion == .motionShake{
let firstRandomNumber = Int(arc4random_uniform(32))
let DrinkString:String = self.drinkNamesArray[firstRandomNumber]
self.drinkImage.image = UIImage(named: DrinkString)
}
}
}
它编译没有错误,IBOutlet是连接,它没有我能看到的错误,但摇动动作不想播放。现在变得非常沮丧。
答案 0 :(得分:1)
您可以尝试使用此代码来代替此部分if motion == .motionShake{
:
if(event.subtype == .motionShake) {
print("Shake event!")
}