Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you flip the coordinate system of an NSView?

I have created an NSScrollView in interface builder that has a variable number of semi-unique NSViews that can be programmatically added and removed from it. When I add subViews to the documentView, they appear in the lower-left hand corner instead of the upper-left hand corner. I see that you can check the isFlipped bool to figure out if the view's coordinate system is flipped, but I cannot find a way to set it as flipped.

Anyone know what I'm missing?

like image 352
rock711 Avatar asked Apr 18 '09 18:04

rock711


2 Answers

In your NSView subclass, override isFlipped:

isFlipped

A Boolean value indicating whether the view uses a flipped coordinate system.

Declaration

var isFlipped: Bool { get } 

Discussion

The default value of this property is false, which results in a non-flipped coordinate system.

[...]

If you want your view to use a flipped coordinate system, override this property and return true.

Source: isFlipped - NSView | Apple Developer Documentation

like image 99
Marc Charbonneau Avatar answered Sep 19 '22 15:09

Marc Charbonneau


For anyone wishing to do this in Swift here's how you override in your custom class:

class FlippedView: NSView {     override var isFlipped {         get {             return true         }     } } 
like image 42
Jay Avatar answered Sep 17 '22 15:09

Jay