Silhouettes of UI elements remain when they are moved within a transparent NSView

Viewed 23

I have a semi-transparent (alpha = 0.4) NSView, which contains other NSViews. Those subviews use mouseDown and mouseDragged to change their positions (by setting new frames) when they are clicked-and-dragged. However, it seems that whenever the views are dragged around, they leave a silhouette (see gif below) of their original position. I have been able to prevent this from happening by changing the background opacity (and then changing it back) every draw cycle, but that slows the drawing calculations down considerably, as expected.

Here's the image (I'm fairly new here, so cannot add the image directly yet): motion silhouette gif

Any insight on what might be going on and how to remedy it would be much appreciated.

Thank you!

EDIT

As requested, here's some relevant code. The NSViews being moved around are all DraggableViews:

class DraggableView: NSView {

    var firstPoint = CGPoint()

    override func mouseDown(with event: NSEvent) {
        firstPoint = (self.window?.contentView?.convert(event.locationInWindow, to: self))!
    }

    override func mouseDragged(with event: NSEvent) {
        let newPoint = (self.window?.contentView?.convert(event.locationInWindow, to: self))!
        let offset = NSPoint(x: newPoint.x - firstPoint.x, y: newPoint.y - firstPoint.y)
        let origin = self.frame.origin
        let size = self.frame.size
        self.frame = NSRect(x: origin.x + offset.x, y: origin.y + offset.y, width: size.width, height: size.height)
    }

}
0 Answers
Related