我是swift的新手。我正在创建一个应用程序,当用户访问应用程序时,它会显示评级应用程序警报框,然后当用户想要输入数字时。同时,键盘和警报框出现在视图上,无法从屏幕上消失。请帮助我解决这个问题,当2个对话框启动时,让用户消失,以响应键盘或评级警报。这是我的代码如下。谢谢你的帮助。
这是导致不解雇的图像: http://imgur.com/a/7Hs9y
MainViewController
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
AppDelegate为我的评级应用提醒。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let shortestTime: UInt32 = 1
let longestTime: UInt32 = 10
guard let timeInterval = TimeInterval(exactly: arc4random_uniform(longestTime - shortestTime) + shortestTime) else { return true }
Timer.scheduledTimer(timeInterval: timeInterval, target: self, selector: #selector(AppDelegate.requestReview), userInfo: nil, repeats: false)
return true
}
@objc func requestReview() {
if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
} else {
// Fallback on earlier versions
}
}
答案 0 :(得分:1)
在Swift 3中,在项目中尝试我的代码并根据需要进行编辑
override func viewDidLoad() {
super.viewDidLoad()
// *** Hide keyboard when tapping outside ***
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapGestureHandler))
view.addGestureRecognizer(tapGesture)
}
func tapGestureHandler() {
view.endEditing(true)
}
我希望它对你有用,
答案 1 :(得分:0)
您可以使用UITapGestureRecognizer隐藏您想要的内容,而不是“touchesBegan”