NSImageView의 하위 클래스가 있으며 CALayer의 인스턴스가 만들어 지므로 이미지에 사각형이 표시됩니다. 질문은 마우스가 아래쪽 (마우스 포인터가 사각형 내부에있을 때)에 드래그하여이 사각형을 이동하는 방법입니다. 마우스를 올리면이 사각형 (CALayer)이 이미지의 새 위치에 있어야합니다. 예를NSImageView에서 CALayer를 이동하는 방법
class ImageViewWithRectangle: NSImageView
{
var shape : CAShapeLayer!
func drawRectangle()
{
shape = CAShapeLayer()
shape.lineWidth = 1.0
shape.fillColor = NSColor.clear().cgColor
shape.strokeColor = NSColor.gray().cgColor
shape.lineDashPattern = [1,1]
self.layer?.addSublayer(shape)
let path = CGMutablePath()
path.moveTo(nil, x: 1, y: 1)
path.addLineTo(nil, x: 1, y: 50)
path.addLineTo(nil, x: 50, y: 50)
path.addLineTo(nil, x: 50, y: 1)
path.closeSubpath()
self.shape.path = path
}
}
나는 지금까지 해본 코드를 보여줄 것을 제안합니다. –
@Jeshua Lacock 예제를 추가했습니다 – VYT
마우스 이벤트는 어디에 있습니까? https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html –