gpt4 book ai didi

swift - 运动摇动 Action 不再 swift 起作用

转载 作者:行者123 更新时间:2023-11-28 15:22:25 29 4
gpt4 key购买 nike

您好,我遇到了一些障碍,我一直在为我的应用程序重新设计菜单导航。我设法做到了。但现在我的应用程序的一项功能已决定停止运行。

想法是你摇动你的手机,它会随机选择一张图片,与应用程序分开的代码工作正常,就像它在所有以前的版本上所做的一样,我什至在它的现有形式上快速运行它以防万一,它运行良好。

希望有人能指出我出错的方向。

我的代码如下;

    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 已连接,没有我能看到的错误,但摇动 Action 不想播放。现在变得非常沮丧。

最佳答案

代替这部分 if motion == .motionShake{ ,你能尝试使用这个吗:

if(event.subtype == .motionShake) {
print("Shake event!")
}

关于swift - 运动摇动 Action 不再 swift 起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45771332/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com