nsview

NSImage from a 1D pixel array?

有些话、适合烂在心里 提交于 2019-12-03 00:51:07
I have a large 1D dynamic array in my program that represents a FITS image on disk i.e. it holds all the pixel values of the image. The type of the array is double . At the moment, I am only concerned with monochrome images. Since Cocoa does not support the FITS format directly, I am reading in the images using the CFITSIO library. This works - I can manipulate the array as I wish and save the result to disk using the library. However, I now want to display the image. I presume this is something NSImage or NSView can do. But the class references don't seem to list a method which could take a C

Overlay NSScroller over content

久未见 提交于 2019-12-03 00:28:01
Is there any way to overlay the NSScroller over the content of the scroll view (like in iOS)? I've already tried several approaches: a) setting the frame of the scroll view content view (NSClipView) to extend into the bounds of the scroller b) adding an NSScroller object as a subview of the scroll view (positioned where I want) c) creating an entirely custom scroller view and placing it as a subview (this worked, but that would mean that I need to rewrite all the functionality of NSScroller) Sparrow seems to successfully do this, and it seems to do it through a regular NSScroller subclass

Distinguishing a single click from a double click in Cocoa on the Mac

浪尽此生 提交于 2019-12-02 21:49:51
I have a custom NSView (it's one of many and they all live inside an NSCollectionView — I don't think that's relevant, but who knows). When I click the view, I want it to change its selection state (and redraw itself accordingly); when I double-click the view, I want it to pop up a larger preview window for the object that was just double-clicked. My first looked like this: - (void)mouseUp: (NSEvent *)theEvent { if ([theEvent clickCount] == 1) [model setIsSelected: ![model isSelected]]; else if ([theEvent clickCount] == 2) if ([model hasBeenDownloaded]) [mainWindowController

How can I get an NSView to resize to fit the desired sizes of its subviews using Auto Layout?

好久不见. 提交于 2019-12-02 21:16:17
I have a superview with three subviews. Two of those subviews are fixed in size and position within the superview, but the third can vary in size depending on its contents. I have set up auto layout constraints to set the size and position of each of the sub views, but what I would like to happen is that when the contents of the third view change, the superview should resize to be able to display it fully. I have implemented - (NSSize) intrinsicContentSize on that subview so that it returns the size it would like to be, but I can't work out how to add a constraint which will trigger the

Layer-backed OpenGLView redraws only if window is resized

≡放荡痞女 提交于 2019-12-02 21:06:50
I have a window with a main view of type NSView and a subview which is a subclass of NSOpenGLView whose name is CustomOpenGLView . The subclass of NSOpenGLView is obtained through a Custom View in Interface Builder and by setting its class to CustomOpenGLView . This is made according to the Apple Sample Code Layer Backed OpenGLView . The app is made to draw something to the OpenGLContext every, let's say, 0.05 seconds. With Core Animation Layer disabled I am able to see the moving object in the view, which is the consequence of the continuous redrawing of the view. And everything works

How to load NSView from Xib with Swift 3

◇◆丶佛笑我妖孽 提交于 2019-12-02 19:08:41
问题 How to load NSView from Xib properly? My code: var topLevelArray: NSArray? = nil let outputValue = AutoreleasingUnsafeMutablePointer<NSArray>(&topLevelArray) if Bundle.main.loadNibNamed("RadioPlayerView", owner: nil, topLevelObjects: outputValue) { let views = outputValue.pointee return views.firstObject as! RadioPlayerView } topLevelArray = nil return nil The problem is "outputValue" is a auto-release pointer, and as soon as I return from the function, the program crash with ACCESS_BAD

How to load NSView from Xib with Swift 3

半世苍凉 提交于 2019-12-02 11:03:40
How to load NSView from Xib properly? My code: var topLevelArray: NSArray? = nil let outputValue = AutoreleasingUnsafeMutablePointer<NSArray>(&topLevelArray) if Bundle.main.loadNibNamed("RadioPlayerView", owner: nil, topLevelObjects: outputValue) { let views = outputValue.pointee return views.firstObject as! RadioPlayerView } topLevelArray = nil return nil The problem is "outputValue" is a auto-release pointer, and as soon as I return from the function, the program crash with ACCESS_BAD_ADDRESS Adam Waite I made an protocol and extension to do this: import Cocoa protocol NibLoadable { static

Can't CTRL+Drag NSButton to custom NSView header

[亡魂溺海] 提交于 2019-12-02 06:21:05
问题 I'd like to create a custom NSTableCellView instantiated by Interface Builder. I've set my Table Cell View class to MyTableCellView , and properly created MyTableCellView : NSTableCellView .m/.h files. However, I just can't CTRL+Drag a simple button from inside this view to MyTableCellView.h in order to create an IBOutlet . Here is a video to show what happens: http://youtu.be/sNNbuVT-SZs. How the view is subclassed: How I try to CTRL+Drag a button Also, sometimes, Interface Builder just don

Multiple views layouting in NSScrollView using Visual AutoLayout

浪尽此生 提交于 2019-12-02 04:18:21
问题 I need to show multiple views aligned vertically inside NSScrollView , I started by adding NSTableView and NSButton . I aligned them vertically with NSTableView on top and NSButton on bottom. I added NSTableview and NSButton to an NSView called tempView . And then set the document view of NSScrollView to tempView . But problem i am having is my tableview does not expand properly i see the buttons alright but tablview does not expands properly and just show the last entries that fits in the

Autolayout constraints do no work for NSView composition with drawRect:

淺唱寂寞╮ 提交于 2019-12-02 02:26:02
问题 I am trying to apply Autolayout constraints to a custom button which inherits from NSView . The button is rather complex and can be used as radio button for example. The user interface is composed in drawRect: as you can guess from the following code excerpt. @interface CustomButton : NSView ... - (void)drawRect:(NSRect)dirtyRect { // ... if (self.hasImage) { // ... if (self.hasTitle) { // ... [image drawInRect:imgRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:fraction