nsview

Multiple threads to draw in NSView

≯℡__Kan透↙ 提交于 2019-12-05 00:21:51
问题 In my code, I subclassed NSView and in its drawRect method, I am spawning three threads to perform the drawing. -(void)drawRect:(NSRect)dirtyRect { [[self window] setAllowsConcurrentViewDrawing:YES]; [self setCanDrawConcurrently:YES]; [NSThread detachNewThreadSelector:@selector(DrawText) toTarget:self withObject:nil]; [NSThread detachNewThreadSelector:@selector(DrawRectangle) toTarget:self withObject:nil]; [NSThread detachNewThreadSelector:@selector(DrawGradient) toTarget:self withObject:nil]

Getting the center point of an NSView

情到浓时终转凉″ 提交于 2019-12-05 00:07:48
I need to get the center point of a NSView in the form of a CGPoint, how can I achieve this? I am basically looking for the equivalent of the UIKit, UIView.center This code will get you that CGPoint: CGPointMake((myView.frame.origin.x + (myView.frame.size.width / 2)), (myView.frame.origin.y + (myView.frame.size.height / 2))) lms A simple and easy to read way is: CGPointMake(NSMidX(myView.frame), NSMidY(myView.frame)) I would suggest making this code, a category on NSView with a read only property named center . To get an NSPoint of the center, you can just get the x-coordinate of the origin

Force NSView to redraw programmatically

ε祈祈猫儿з 提交于 2019-12-04 22:29:38
问题 My app has two different states, and every state will be representing with a NSView. so there is only one view showed at a time, the problem is when I switched between the views the app doesn't show the new state until I resize the window manually! I searched about this problem and come with more than one solution but nothing worked with me: [myView setNeedsDisplay:YES]; [myView display]; [[myView.window contentView] setNeedsDisplay:YES]; [mySubView1 setHidden:YES]; || [mySubView1

Adding an NSProgressIndicator to the dock icon

僤鯓⒐⒋嵵緔 提交于 2019-12-04 19:37:35
问题 I'm creating an application which should show a progress bar in the dock icon. Currently I have this, but it's not working: NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 10.0f, 20.0f)]; [progressIndicator setStyle:NSProgressIndicatorBarStyle]; [progressIndicator setIndeterminate:NO]; [[[[NSApplication sharedApplication] dockTile] contentView] addSubview:progressIndicator]; [progressIndicator release]; Or must I draw it on the dock

What's the preferred/recommended way to draw a line in NSView-drawRect: method?

假装没事ソ 提交于 2019-12-04 19:14:58
问题 I couldn't found any line drawing primitive in Cocoa at NSView level. The only thing I've been found is NSBezierPath . Is this a preferred way? Or is there another way which I couldn't discovered? 回答1: NSBezierPath is exactly what you should be using. If you just want to draw a straight line from one point to another, use the class method: +strokeLineFromPoint:(NSPoint)point1 toPoint:(NSPoint)point2 回答2: Cocoa uses an implicit drawing stack, and an invalidation model. In your NSView, when

How exactly does an NSView, an NSViewController, and MainMenu.xib fit together?

社会主义新天地 提交于 2019-12-04 15:18:16
I'm going to cut right to the chase: my application has grown quite a bit, and now I think it's time for me to do some tidying up. I want to separate some of my views from my MainMenu.xib file into their own Nib file. The part that's tripping me up is the whole "Interface Builder + My Code" thing. Here's what I've done so far: I've added a view controller proxy object: In the Identity inspector, I've added my view controller's class name to the Custom Class field. In the Attributes inspector, I've entered the name of the Nib I want to load up. I've connected the view controller object's view

Interface Builder: How to load view from nib file

≯℡__Kan透↙ 提交于 2019-12-04 14:28:57
问题 I have a MyCustomView subclassed from NSView designed in a .xib. I would like to insert this view into some of my other xib's round my application. How should I do this? If i drag a custom view and change the class to MyCustomView, but that does not load my xib-file. Can this only be done programmatically or is there a way to do this inside interface builder? EDIT1: Here is a very small demo-project: http://s000.tinyupload.com/index.php?file_id=09538344018446482999 It contains the default

Rounded NSView in a Transparent Window

爱⌒轻易说出口 提交于 2019-12-04 11:28:06
I'm trying to make a transparent NSWindow with a rounded view in there. I'm trying to have a rounded view with a transparent window. This is what it looks like now: (see the little dots in the corners) Here's another example with the border radius set to 10px (set in NSView drawRect): I am using code from this Apple sample: https://developer.apple.com/library/mac/#samplecode/RoundTransparentWindow/Introduction/Intro.html Specifically this method in my NSWindow subclass: - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:

How does an NSView subclass communicate with the controller?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 09:25:32
问题 I am brand spanking new to Cocoa programming, and am still kind of confused about how things wire together. I need a pretty simple application that will fire off a single command (let's call it DoStuff ) whenever any point on the window is clicked. After a bit of research it looks like subclassing NSView is the right way to go. My ClickerView.m file has this: - (void)mouseDown:(NSEvent *)theEvent { NSLog(@"mouse down"); } And I have added the View to the Window and have it stretching across

Layer-backed OpenGLView redraws only if window is resized

只谈情不闲聊 提交于 2019-12-04 08:09:56
问题 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