appkit

How to implement zoom/scale in a Cocoa AppKit-application

廉价感情. 提交于 2019-12-04 12:24:06
问题 How do you implement zoom/scale in a Cocoa AppKit-application (i.e. not maximizing the window but scaling the window and all its subviews)? I think it's called zoomScale in iOS. Can it be done using Core Animations or Quartz 2D (e.g. CGContextScaleCTM ) or am I forced to implement it manually in all my NSViews, NSCells, etc? 回答1: Each NSView has a bounds and frame, the frame is the rectangle that describes a view's placement within its superview's bounds. Most views have a bounds with a zero

How does +[NSColor selectedMenuItemColor] magically draw a gradient?

喜夏-厌秋 提交于 2019-12-04 11:07:51
I'm implementing a custom NSMenuItem view that shows a highlight as the user mouses over it. To do this, the code calls NSRectFill after setting [NSColor selectedMenuItemColor] as the active color. However, I noticed that the result is not simply a solid color — it actually draws a gradient instead. Very nice, but wondering how this "magic" works — i.e. if I wanted to define my own color that didn't just draw solid, how would I? I don't know how this actually works, but I found a way to replicate the behavior with custom gradients (or any other drawing operations). The "trick" is to use a

Cocoa predefined resize mouse cursor?

半腔热情 提交于 2019-12-04 08:31:10
Is the resize mouse cursor used by Preview (e.g. when resizing shapes) a system cursor? It's not available directly as a method in NSCursor but then it doesn't look like there's a private resource for the cursor in the Preview app's bundle either.. Are there more system cursors other than the methods defined by the NSCursor class..? I think you are particularly interested in these class methods (Preview.app dissasembly). +[NSCursor resizeAngle45Cursor]; which calls +[NSCursor _windowResizeNorthEastSouthWestCursor]; +[NSCursor resizeAngle135Cursor]; which calls +[NSCursor

How do find out if there is a full-screen app running on a specific NSScreen

纵然是瞬间 提交于 2019-12-04 07:02:27
In Cocoa/AppKit, given a screen from [NSScreen screens] , how can I find out if there's a full-screen app running on that specific screen? I'm mostly interested in apps that use the Cocoa APIs for full-screen, but if there's a solution that also encompasses other types of full-screen apps, even better. The solution needs be able to pass Mac App Store approval. My specific use case involves a menu bar app ( NSStatusItem ) and figuring out whether or not a menubar is shown at all on [NSScreen mainScreen] in order to allow a global keyboard shortcut to show either a popover positioning on the

Why isn't applicationShouldOpenUntitledFile being called?

给你一囗甜甜゛ 提交于 2019-12-04 03:53:34
I added a applicationShouldOpenUntitledFile method to my application delegate, returning NO as Apple's documentation specifies. However, I'm still getting a new document on startup. What's wrong? @implementation AppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSLog( @"This is being called" ); } - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender { NSLog( @"This never is" ); return NO; } @end You're running Lion. When you ran before adding the applicationShouldOpenUntitledFile handler, a new document was created. Now, with 10

How to make an alert controller in mac using swift

≯℡__Kan透↙ 提交于 2019-12-04 02:13:19
问题 I am new to Swift, and I'm trying to make a score collected program for Mac OS X. I do know about Swift programming on iOS, but I don't know that much about OS X Swift. So I wrote a program for OS X. I almost finished it, but i want to know how to make alert controller in mac using swift. I know how to do it on iso but i don't know how to do it on OS X and also i want to know how to use .isEmpty in OS X. import Cocoa class ViewController: NSViewController { @IBOutlet var Maths: NSTextField! =

Hide scrollers while leaving scrolling itself enabled in NSScrollView

荒凉一梦 提交于 2019-12-04 00:34:06
问题 I'd like to hide the NSScroller s of NSScrollView . I'm aware of the methods setHasHorizontalScroller: and setHasVerticalScroller: . However, if I disable the scrollers, scrolling in that direction gets disabled as well. I'd like to only hide the scrollers while maintaining the possibility to scroll. Any thoughts on this? 回答1: I was able to do this by doing: [labelsScrollView setHasHorizontalScroller:YES]; [[labelsScrollView horizontalScroller] setAlphaValue:0]; 回答2: The trick of setting

Transparent background WKWebView (NSView)

一曲冷凌霜 提交于 2019-12-03 17:19:53
问题 I am building a Mac application using Swift. Therefor, I want to make a WKWebView transparent, so it shows the text of the loaded HTML, but the background of my underlaying NSWindow is visible. I tried webView.layer?.backgroundColor = NSColor.clearColor().CGColor; which hadn't any effect. WKWebView inherits from NSView, but I don't know if this helps. Another solution would be to insert a NSVisualEffectView as the background of the WebView, but I don't know how to accomplish that, either! 回答1

Debugging Help Book (“The selected topic is currently unavailable”)

心不动则不痛 提交于 2019-12-03 17:15:24
Right - so I've created a help book, did all the right things , double-checked my plist and index.html files, and all I get is the notorious The selected topic is currently unavailable. The only entry in Console when attempting to open the help book is a plain 3/8/15 1:23:42.467 PM HelpViewer[35015]: Couldn't find book with this ID: (null) Not too helpful. Where to go from here? Are there any debugging techniques for Apple Help? Logging to turn on? Anything..? Just struggled a few hours with the same problem. The ID: (null) means that you are missing CFBundleName or HPDBookTitle keys, or

How to make NSView not clip its bounding area?

喜你入骨 提交于 2019-12-03 12:36:59
问题 I created an empty Cocoa app on Xcode for OS X, and added: - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.view = [[NSView alloc] initWithFrame:NSMakeRect(100, 100, 200, 200)]; self.view.wantsLayer = YES; self.view.layer = [CALayer layer]; self.view.layer.backgroundColor = [[NSColor yellowColor] CGColor]; self.view.layer.anchorPoint = CGPointMake(0.5, 0.5); self.view.layer.transform = CATransform3DMakeRotation(30 * M_PI / 180, 1, 1, 1); [self.window.contentView