nsview

Make NSView in NSPanel first responder without key window status

家住魔仙堡 提交于 2019-11-30 15:34:24
Is it possible to give an NSView inside an NSPanel first responder status without giving the NSPanel key window status (making the main application window resign key)? Thanks. Well, I ended up figuring this one out, but it took a lot of research so I'll post the details here in case anyone else runs into the same problem. First of all, a few basics: It's impossible to have 2 windows actually be key at the same time It's possible to fake a window into thinking it's key by overriding -isKeyWindow but that won't give the views contained in the window first responder status. My Scenario: I added a

Why are subviews of an NSView not sent a release message when a Cocoa application terminates?

两盒软妹~` 提交于 2019-11-30 14:02:38
The short version: Why are the subviews of NSView objects not sent a release message when a Cocoa application terminates? Is there a way to override this behaviour? An example: The MyView class shown below is nothing more than an NSView subclass that reports to the console when it is created and destroyed. I have tested it out and found it to work properly. However, when I use it as shown in the next code snippet from my application delegate, I see something unexpected (see sample output). // MyView: @interface MyView : NSView { } @end @implementation MyView - (id)initWithFrame:(NSRect

NSView's autoresizing behavior

血红的双手。 提交于 2019-11-30 12:19:44
问题 I need to understand how NSView autoresizes it's views. I've set everything up in IB and my subviews resize nicely (when I resize my window around with a mouse). However, if I do [myMainView setFrame:] with my new frame rect, nothing happens. All of my sub-views are still the original size (even though the main view has the correct dimensions). Child's resizeWithOldSuperviewSize: gets called, but it's still not appropriately sized. I have a screen-full of cocoa elements on screen (screen #1),

Converting an NSPoint from window coordinates to view coordinates

拈花ヽ惹草 提交于 2019-11-30 08:35:05
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 which displays detail information about an event when the user clicks that event in the timeline. Below is the code that handles the event when it is received by the timeline: NSEvent *anEvent = [aNotification object]; NSPoint aLocationInSelf = [self convertPoint: [anEvent locationInWindow] toView: self]; // Create callout view and display NSRect aRect

How to detect right and left click in cocoa

做~自己de王妃 提交于 2019-11-30 07:43:30
I want to create a action on right and left click of mouse. Click may be on NSTableViewCell, NSView, etc (Like when we right click on window it gives a pop-up ) . Is there any API to do such task? If no, any other way . Thank you in advance for helping me. Ramy Al Zuhouri You have to override NSResponder methods like: - (void) mouseDown: (NSEvent*) theEvent; - (void) rightMouseDown: (NSEvent*) theEvent; Reference: NSResponder Documentation . Update: as mentioned below, NSView and NSTableView inherits these methods from NSResponder. NSView and NSTableView inherits from NSResponder and

Get ALL views and subview of NSWindow

最后都变了- 提交于 2019-11-30 06:47:06
问题 Is there a way I can get ALL the views and subviews and subviews of these subviews (you get the idea...) of an NSWindow? Thanks. 回答1: Here is a category on NSView: @interface NSView (MDRecursiveSubviews) - (NSArray *)allSubviews; @end @implementation NSView (MDRecursiveSubviews) - (NSArray *)allSubviews { NSMutableArray *allSubviews = [NSMutableArray arrayWithObject:self]; NSArray *subviews = [self subviews]; for (NSView *view in subviews) { [allSubviews addObjectsFromArray:[view allSubviews]

Setting backgroundColor of custom NSView

假装没事ソ 提交于 2019-11-30 03:46:16
What is the process of drawing to NSView using storyboards for osx? I have added a NSView to the NSViewController. Then, I added a few constraints and an outlet. Next, I added some code to change the color: import Cocoa class ViewController: NSViewController { @IBOutlet var box: NSView! override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear() { box.layer?.backgroundColor = NSColor.blueColor().CGColor //box.layer?.setNeedsDisplay() } override var representedObject: AnyObject? { didSet { // Update the view, if already loaded. } } } I would like to do custom drawing and

How do I make an NSView move to the front of all NSViews

元气小坏坏 提交于 2019-11-30 02:49:58
I have a super view, which has 2 subviews. These subviews are overlapped. Whenever i choose a view from a menu, corresponding view should become the front view and handle actions. i.e., it should be the front most subview. acceptsFirstResponder resigns all work fine. But the mouse down events are sent to the topmost sub view which was set. Regards, Dhana Here's another way to accomplish this that's a bit more clear and succinct: [viewToBeMadeForemost removeFromSuperview]; [self addSubview:viewToBeMadeForemost positioned:NSWindowAbove relativeTo:nil]; Per the documentation for this method, when

NSView's autoresizing behavior

喜你入骨 提交于 2019-11-30 02:29:47
I need to understand how NSView autoresizes it's views. I've set everything up in IB and my subviews resize nicely (when I resize my window around with a mouse). However, if I do [myMainView setFrame:] with my new frame rect, nothing happens. All of my sub-views are still the original size (even though the main view has the correct dimensions). Child's resizeWithOldSuperviewSize: gets called, but it's still not appropriately sized. I have a screen-full of cocoa elements on screen (screen #1), label, image, video. There's a well-defined layout for these elements. I've setup autoresizing

Easy Switching of “View Controllers” in Mac Apps (similar to iOS)

只愿长相守 提交于 2019-11-30 02:29:34
I am coming from an iOS background and am new to Mac OSX (coco app) development. Starting with apple sample code project " Simple Cocoa App " as a base, I want to be able to switch between different "View Controllers" or even just between NSViews in any manner similar to that of iOS apps. Unfortunately, I could not find a way to accomplish this -- and the internet is rather lacking in resources tied to keywords like "View switching in cocoa apps, switching views in mac apps, mac app dev tutorials"... Do any of you know a tutorial that, and here's the kicker, actually covers the matter of