appkit

How to intercept keystrokes from within the field editor of an NSTextField?

大憨熊 提交于 2019-12-22 08:25:18
问题 Intro When my custom NSTextField is in "text editing mode" and the field editor has been placed in front of it as firstResponder I no longer get the keystrokes through NSTextField.keyDown(...) . I understand that the keystrokes are now being routed through the field editor . Most online recommendations are to override the following method within the delegate of the custom NSTextField : control(_:textView:doCommandBySelector:) I have indeed overridden this method but it doesn't seem to get

How to get notified when NSWindow closes

天大地大妈咪最大 提交于 2019-12-22 02:20:26
问题 how can I take notice when an NSWindow should or will get closed? I'd like to have something like the windowWillClose. Unfortunately NSWindowController does not have as much convenient methods as UIViewController has, for example. So what's the best practice to do that? Thanks –f 回答1: According to the NSWindow docs, a window will post a NSWindowWillCloseNotification notification when it is about to close. Your controller can observe this notification. 来源: https://stackoverflow.com/questions

Cocoa predefined resize mouse cursor?

岁酱吖の 提交于 2019-12-21 16:54:37
问题 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..? 回答1: I think you are particularly interested in these class methods (Preview.app dissasembly). +[NSCursor resizeAngle45Cursor]; which calls +[NSCursor

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

有些话、适合烂在心里 提交于 2019-12-21 13:48:30
问题 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

Vertically aligning text in an NSTextField using Swift

不打扰是莪最后的温柔 提交于 2019-12-21 03:57:26
问题 I have been reading through the various options on how to set the vertical alignment on an NSTextField. I want the text to be displayed in the center and to do it programatically in Swift. Here are the things I have looked so far: http://www.cocoabuilder.com/archive/cocoa/174994-repositioning-an-nstextfieldcell.html https://red-sweater.com/blog/148/what-a-difference-a-cell-makes Vertically Centre Text in NSSecureTextField with subclassing Get NSTextField contents to scale vertically align

Encoding NSViewController for Lion's user interface resume feature

二次信任 提交于 2019-12-19 01:41:21
问题 Any idea what are the best practices for archiving an NSViewController inside a window for resume (user interface preservation) purposes? I've tried archiving it in the window controller's encodeRestorableStateWithCoder: methods only to find out that the view controller doesn't get unarchived when restoreStateWithCoder: is called. // NSWindowController subclass -(void)encodeRestorableStateWithCoder:(NSCoder *)coder { [super encodeRestorableStateWithCoder:coder]; NSViewController*

Encoding NSViewController for Lion's user interface resume feature

ε祈祈猫儿з 提交于 2019-12-19 01:38:34
问题 Any idea what are the best practices for archiving an NSViewController inside a window for resume (user interface preservation) purposes? I've tried archiving it in the window controller's encodeRestorableStateWithCoder: methods only to find out that the view controller doesn't get unarchived when restoreStateWithCoder: is called. // NSWindowController subclass -(void)encodeRestorableStateWithCoder:(NSCoder *)coder { [super encodeRestorableStateWithCoder:coder]; NSViewController*

Force NSMenu (nested submenu) update for Main Menu of Cocoa App

半腔热情 提交于 2019-12-18 12:42:30
问题 I have some submenu inserted as Window item submenu of Main Menu I have an instance of my object (let's assume its class name is MenuController) inherited from NSObject and supports 2 from NSMenuDelegate methods: – numberOfItemsInMenu: – menu:updateItem:atIndex:shouldCancel: This instance added as Blue-Object into NIB for awaking at runtime Object from steps 2-3 configured as delegate for submenu (step 1) Now, I can provide submenu content in runtime. Next, I do following: I can add new items

Get Certificates in Keychain

若如初见. 提交于 2019-12-17 22:42:18
问题 I've looked over the Security framework documentation but I can't seem to be able to find a way to get all of the certificates on a given keychain. Are there methods to accomplish this? 回答1: After mining the documentation, header files, and source files, I’ve come up with the following code: #import <Security/Security.h> - (void)logMessageForStatus:(OSStatus)status functionName:(NSString *)functionName { CFStringRef errorMessage; errorMessage = SecCopyErrorMessageString(status, NULL); NSLog(@

Why does NSToolbarItem get disabled automatically?

对着背影说爱祢 提交于 2019-12-14 01:24:02
问题 I have a bit of an issue with buttons in the toolbar of my slideshow application for Mac. I want those buttons to be disabled when there is no active slideshow and enabled when there is an active slideshow. In order to achieve this, I set the buttons' isEnabled property to false at the start (I have tried both Interface Builder and my window's windowDidLoad ) and then in the didSet of my slideshow variable I do the following: var slideshow: Slideshow? { didSet { self.playPauseButton.isEnabled