首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swipe手势给NSException

Swipe手势给NSException
EN

Stack Overflow用户
提问于 2017-02-25 02:59:13
回答 1查看 43关注 0票数 0

我是swift编程的新手。因此,我尝试在我的iOS应用程序中添加滑动手势。但当我试图滑动它时,应用程序停止了,并显示NSException caught。这是我写的代码。

代码语言:javascript
复制
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
        }
    }
}

我还尝试向我的viewController类添加UIGestureRecognizerDelegate,如下所示

代码语言:javascript
复制
class ViewController: UIViewController, UIGestureRecognizerDelegate

但它并没有起作用。我还添加了UIGestureRecognizer。请帮帮我,我真的被困在这里了。我正在使用Xcode8和OSX El Capitan。提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-25 03:08:34

对于新的#selector(),字符串类型的Selector()已被弃用。

将您的操作更新为#selector(gesture(gesture:)),这样应该可以修复它

代码语言:javascript
复制
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(gesture(gesture:)))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42446324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档