nsview

Get ALL views and subview of NSWindow

心不动则不痛 提交于 2019-11-28 23:36:27
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. 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]]; } return [[allSubviews copy] autorelease]; } @end With a quick nib file I created with a view hierarchy,

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

心已入冬 提交于 2019-11-28 23:24:58
问题 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

Saving an NSView to a png file?

本小妞迷上赌 提交于 2019-11-28 22:02:46
I am making a simple program that creates game cards for a game I play. I have sent it out to some friends of mine for testing, but they really want it to save images, not just print them. I have tried to make it save as a .png file. I have to questions here. How can I make it save my view as a .png file, including all of the view's NSImageWells. How can I add an NSPopupButton to an NSSavePanel to allow users to select a format? Any help is greatly appreciated. First create a TIFF representation of your view: // Get the data into a bitmap. [self lockFocus]; rep = [[NSBitmapImageRep alloc]

Drawing selection box (rubberbanding, marching ants) in Cocoa, ObjectiveC

会有一股神秘感。 提交于 2019-11-28 17:58:31
问题 I've currently implemented a simple selection box using mouse events and redrawing a rectangle on mouse drag. Here's my code: -(void)drawRect:(NSRect)dirtyRect { if (!NSEqualRects(self.draggingBox, NSZeroRect)) { [[NSColor grayColor] setStroke]; [[NSBezierPath bezierPathWithRect:self.draggingBox] stroke]; } } #pragma mark Mouse Events - (void)mouseDown:(NSEvent *)theEvent { NSPoint pointInView = [self convertPoint:[theEvent locationInWindow] fromView:nil]; self.draggingBox = NSMakeRect

NSWindow with round corners and shadow

倾然丶 夕夏残阳落幕 提交于 2019-11-28 16:02:48
问题 I'm trying to crate a NSWindow without title bar ( NSBorderlessWindowMask ) with round corners and a shadow, similar to the below "Welcome to Xcode" window. I make a subclass of NSWindow : @implementation FlatWindow - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag { self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:bufferingType defer:flag]; if ( self ) { [self setOpaque

Are layer-backed NSView siblings allowed to overlap?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 08:33:48
I'm a little confused. The Apple Documentation states this: Note: For performance reasons, Cocoa does not enforce clipping among sibling views or guarantee correct invalidation and drawing behavior when sibling views overlap. If you want a view to be drawn in front of another view, you should make the front view a subview (or descendant) of the rear view. So according to this, sibling views should not overlap or else the behavior is undefined. In the Cocoa Slides demo app , however, layer-backed NSView siblings do overlap and it seems to work just fine: So is the Cocoa Slides sample code wrong

Backward compatibility of Xcode OSX

本秂侑毒 提交于 2019-11-28 05:35:03
问题 How to use features such as viewDidLoad or appDidBecomeActive in Xcode 4.6.1 for OSX 10.8, which are available only for OSX 10.10 and above. Please suggest the alternative ways to use these functions. 回答1: To expand on Ken Thomas's comment; this is the code that I use: - (void)loadView { [super loadView]; // if we're running on 10.8 or older… if (NSAppKitVersionNumber <= NSAppKitVersionNumber10_8) { [self viewDidLoad]; // call viewDidLoad (added in 10.9) } } // // This will be called by

Selection Highlight in NSCollectionView

柔情痞子 提交于 2019-11-28 04:31:11
I have a working NSCollectionView with one minor, but critical, exception. Getting and highlighting the selected item within the collection. I've had all this working prior to Snow Leopard, but something appears to have changed and I can't quite place my finger on it, so I took my NSCollectionView right back to a basic test and followed Apple's documentation for creating an NSCollectionView here: http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/CollectionViews/Introduction/Introduction.html The collection view works fine following the quick start guide. However, this guide

Get Image from CALayer or NSView (swift 3)

房东的猫 提交于 2019-11-28 03:16:44
问题 I was looking for a way to render CALayer or NSView and get NSImage back. I have a custom class which is a subclass of NSView. In the beginning I simply make a gradient layer to cover all NSView. class ContentView: NSView { override func draw(_ dirtyRect: NSRect) { fillGradientLayer() } func fillGradientLayer() { gradientLayer = CAGradientLayer() gradientLayer.colors = [#colorLiteral(red: 0, green: 0.9909763549, blue: 0.7570167824, alpha: 1),#colorLiteral(red: 0, green: 0.4772562545, blue: 1,

How to disable user interaction in a custom View

徘徊边缘 提交于 2019-11-28 02:46:40
问题 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? 回答1: NSView doesn't have either setEnabled: or setIgnoresMouseEvents: Implement the hitTest: method to return nil . 回答2: From here: // // NSView-DisableSubsAdditions.m // Can Combine Icons // // Created by David Remahl on Tue Dec 25 2001. //