我是swift編程的新手。所以我試圖在iOS的應用程序中添加滑動手勢。但是,當我嘗試刷卡停止應用程序,並說NSException發生。這是我寫的代碼。滑動手勢給NSException
override func viewDidLoad() {
super.viewDidLoad()
textLabels.append(label0)
textLabels.append(label1)
textLabels.append(label2)
textLabels.append(label3)
textLabels.append(label4)
textLabels.append(label5)
textLabels.append(label6)
textLabels.append(label7)
textLabels.append(label8)
textLabels.append(label9)
textLabels.append(label10)
textLabels.append(label11)
textLabels.append(label12)
textLabels.append(label13)
textLabels.append(label14)
textLabels.append(label15)
setupInitial()
print(textLabels.count)
var request = GADRequest()
request.testDevices = [kGADSimulatorID]
bannerView.adUnitID = "ca-app-pub-8950283126375215/1694851281"
bannerView.rootViewController = self
bannerView.load(request)
createAndLoadInterstitial()
let swipeRight = UISwipeGestureRecognizer(target: self, action: Selector(("gesture:")))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)
let swipeDown = UISwipeGestureRecognizer(target: self, action: Selector(("gesture:")))
swipeDown.direction = UISwipeGestureRecognizerDirection.down
self.view.addGestureRecognizer(swipeDown)
//setView(view: hideView, hidden: false)
}
func gesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.right:
print("Swiped right")
case UISwipeGestureRecognizerDirection.down:
print("Swiped down")
case UISwipeGestureRecognizerDirection.left:
print("Swiped left")
case UISwipeGestureRecognizerDirection.up:
print("Swiped up")
default:
break
}
}
}
我也嘗試添加UIGestureRecognizerDelegate我的viewController類這樣
class ViewController: UIViewController, UIGestureRecognizerDelegate
,但沒有奏效。我還添加了UIGestureRecognizer。請幫助我,我真的被困在這裏。我正在使用Xcode 8和OSX El Capitan。提前致謝。
什麼是例外,它拋出? – Bienemann
@Bienemann感謝您的回覆,但我的問題是通過下面的答案解決的。 – Antzion