Questions tagged [nsview]

NSView Implements basic drawing, event handling and printing behaviors for applications. Usually application code define subclasses of NSView to provide richer implementations. Belongs to the Foundation framework for Cocoa and Cocoa Touch.

The NSView class defines the basic drawing, event-handling, and printing architecture of an app. You typically do not use NSView objects directly. Instead, you use objects whose classes descend from NSView or you subclass NSView yourself and override its methods to implement the behavior you need. For any view object, there are many methods that you can use as-is.

1639 questions
19
votes
6 answers

mouseMoved not called

I have a subclassed NSView which is part of a .xib-file of a subclassed NSDocument, which gets alive by the default behaviour of NSDocumentController's openDocument: method. In this subclassed NSView I have implemented the methods awakeFromNib, in…
Dominik Seibold
  • 2,439
  • 1
  • 23
  • 29
19
votes
5 answers

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

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…
James Williams
  • 1,861
  • 1
  • 15
  • 21
19
votes
3 answers

How to add an NSView to NSWindow in a Cocoa app?

Since the template of an OS X app in Xcode seems to be similar to an empty app template, the following is used to add a view and a button (trying not to use Interface builder for now): - (void)applicationDidFinishLaunching:(NSNotification…
Jeremy L
  • 3,770
  • 6
  • 41
  • 62
18
votes
2 answers

drawrect Vs layoutsubviews - NSView - Cocoa touch

I can't find a decent answer to explain me the difference between these 2 functions. when does every one gets called, and how does one different then the other ? for example , can't I just layout my views inside drawrect ? Thanks
Idan
  • 5,717
  • 10
  • 47
  • 84
18
votes
4 answers

How do I take a "screenshot" of an NSView?

I need to take the contents of an NSView and put them in an NSImage, for an experimental project. Is this possible? I did some Googling, tried two methods that I found - but they didn't really work. Any suggestions?
Debashis
  • 199
  • 1
  • 1
  • 4
18
votes
5 answers

How to disable user interaction in a custom View

I have a custom View NSView and I want to disable userinteraction, but I'm not sure how to do this. My idea was: [myView setEnabled:NO]; but it's wrong and doesn't work. How can I make it so that, it's just visible for the user, and nothing else?
Viper OS X
  • 291
  • 1
  • 5
  • 14
18
votes
3 answers

How to disable Click through to a NSView behind another NSView

I have two NSViews on top of each other. One NSView presents a table with rows. On clicking a row another view is shown on top of that view. Now the problem is when I click on an area on the second view where there is a row on the underneath NSView…
Leo
  • 1,547
  • 3
  • 24
  • 40
17
votes
1 answer

Converting an NSPoint from window coordinates to view coordinates

My application has a custom view that displays a timeline of events. This view is wrapped in an NSScrollView to support horizontal scrolling of the timeline. Using notifications, I've implemented a mechanism that should show another custom view…
Roger
  • 4,737
  • 4
  • 43
  • 68
15
votes
4 answers

Binding a custom NSView: Does it demand creating an IBPlugin?

I have created a subclass of NSView to draw an image as a pattern: @interface CePatternView : NSView { NSImage* image; id observableObjectForImage; NSString* keyPathForImage; } @end I implemented the following to expose…
Renaud Pradenc
  • 1,221
  • 2
  • 8
  • 9
15
votes
2 answers

CustomView looks odd in my project, but good in the playground

So I've created a custom NSButton to have a beautiful radio button, but I'm experiencing a very weird bug. My radio button looks good in the playground, but when I add it to my project, it looks odd. Here are screenshots: Left = in the…
Vin Gazoil
  • 1,942
  • 2
  • 20
  • 24
15
votes
1 answer

Detect left and right mouse click on NSView

In Swift: I created a simple NSView and now want to execute different functions, depending on which mouseButton is pressed (left or right). how can I detect this?
ixany
  • 5,433
  • 9
  • 41
  • 65
15
votes
1 answer

NSResponder not receiving keyUp event when Cmd ⌘ key held down

I'm using a custom subclass of NSView and receiving keyboard events through the keyDown/keyUp methods, everything works fine except when the "Cmd ⌘" key is pressed, keyDown events are fired as normal but the keyUp event never comes. In our case we…
Jez Cooke
  • 151
  • 4
14
votes
2 answers

Adding a custom view to toolbar

I'm struggling with Cocoa for 2 hours now without success. I want to add a custom view to the toolbar. So, I added a NSToolbar to the window (with IB), and added my view (which works perfectly). IB automatically created a NSToolbarItem. I followed…
user531461
14
votes
3 answers

Subclassing NSView to have a transparent background

I am creating an app where I need to have a transparent NSView with a transparent PNG image inside. The problem is, the NSView I'm drawing has a gray background on it. I have it subclassed (as TransparentRectangleView) but don't know what to put in…
Andrew M
  • 4,208
  • 11
  • 42
  • 67
14
votes
1 answer

Get Image from CALayer or NSView (swift 3)

I was looking for a way to render a CALayer or NSView and get NSImage back. I have a custom class, which is a subclass of NSView. At the beginning I simply make a gradient layer to cover NSView. class ContentView: NSView { override func draw(_…
Alexei
  • 511
  • 1
  • 10
  • 22