Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何在macOS上使用AppKit使鼠标滚轮水平滚动_Swift_Macos_Cocoa_Appkit - Fatal编程技术网

Swift 如何在macOS上使用AppKit使鼠标滚轮水平滚动

Swift 如何在macOS上使用AppKit使鼠标滚轮水平滚动,swift,macos,cocoa,appkit,Swift,Macos,Cocoa,Appkit,我的应用程序只有一行的NSCollectionView。我想用鼠标滚轮使其水平滚动,但不想同时按下shift键 因此,如何使用macOS上的AppKit转换滚动方向?您可以将NSCollectionView子类化并覆盖scrollWheel import Cocoa class YourCollectionView: NSCollectionView { override func scrollWheel(with event: NSEvent) { // get m

我的应用程序只有一行的NSCollectionView。我想用鼠标滚轮使其水平滚动,但不想同时按下shift键


因此,如何使用macOS上的AppKit转换滚动方向?您可以将NSCollectionView子类化并覆盖scrollWheel

import Cocoa

class YourCollectionView: NSCollectionView {

    override func scrollWheel(with event: NSEvent) {
        // get mouse wheel scroll offset
        let scrollOffset = event.scrollingDeltaY

        // scroll collectionView your self, maybe like this
        if let clipView = self.enclosingScrollView?.contentView as? NSClipView {
            let currentPoint = self.visibleRect.origin
            let newPoint = CGPoint(x: currentPoint.x + scrollOffset ,y: currentPoint.y)
            clipView.scroll(to: newPoint)
        }
    }
}
你可以试一试,希望这能对你有所帮助