Day: May 18, 2016

Swift:マウスイベント(コードで定義)

コードでマウスイベントを書くサンプルで調べています。

swipeとpamのサンプルがあります。どちらもほとんど同じなのですが、なぜか、swipeはうまくいきません。pamは制御が渡ってくるのでOKです。NSGestureRecognizerの書き方がまずいのかもしれません。

@IBOutlet var   xWebView:WebView?
@IBOutlet var   xView:NSView!

xView.acceptsTouchEvents = true
xWebView!.acceptsTouchEvents = true
//————————————-swipe NG
let wSwipeGesture:NSGestureRecognizer=NSGestureRecognizer()
wSwipeGesture.enabled                 = true
wSwipeGesture.target                    = self
wSwipeGesture.action                    = #selector(self.ExecSwipe(_:))
//xView.addGestureRecognizer(wSwipeGesture)
xWebView!.addGestureRecognizer(wSwipeGesture)
//————————————-pan OK
let wSpanGesture:NSPanGestureRecognizer=NSPanGestureRecognizer()
wSpanGesture.enabled                  = true
wSpanGesture.target                     = self
wSpanGesture.action                     = #selector(self.ExecPan(_:))
//xView.addGestureRecognizer(wSpanGesture)
xWebView!.addGestureRecognizer(wSpanGesture)

//————————————-

override func touchesMovedWithEvent(event: NSEvent) {//無関係?
        if (event.type == .EventTypeGesture) {
            swipeWithEvent(event)
        }
}
override func touchesBeganWithEvent(event: NSEvent) {//無関係?

}
override func touchesEndedWithEvent(event: NSEvent) {//無関係?

}
func ExecPan(event: NSEvent) {
        print(“Pan = \(event)”)
}
func ExecSwipe(event: NSEvent) {

}
override var acceptsFirstResponder: Bool {//無関係?
        return true
}