【问题标题】:Swift - How do you tell when a NSScrollView starts to scroll?Swift - 你如何判断 NSScrollView 何时开始滚动?
【发布时间】:2016-07-06 01:28:40
【问题描述】:

在 Swift 中是否有办法判断 NSScrollView 何时开始滚动。

【问题讨论】:

    标签: swift macos nsscrollview


    【解决方案1】:

    你可以使用监听NSScrollViewWillStartLiveScrollNotification[1]的观察者

    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourClass.YourFunctionName), name: NSScrollViewWillStartLiveScrollNotification, object: nil)
    

    只需将你的函数放在#Selector()

    【讨论】:

    • 我收到 2 个错误:“表达式列表中的预期表达式”和“预期的 ',' 分隔符”。这是我的声明:NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector("resetScroller"), name: NSScrollViewWillStartLiveScrollNotification, object: nil)。 XCode 想在 'selector:' 和 '#selector()' 之间添加一个逗号。
    • #selector 是一个 objc c 类型的选择器。如果你在 ViewController 类中有一个函数 doSomething() 你使用 #selector(ViewController.doSomething(:))
    • 我发现不是#selector,而是使用Selector("functionName")。
    • #selector 是自 swift 2.2 以来的新功能,并为拼写错误提供保护,基于字符串的函数名称将被弃用:swift.org/blog/swift-2-2-new-features
    • 这在用户使用鼠标滚轮滚动时不起作用。
    猜你喜欢
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多