appkit

How to check if an NSWindow is open

穿精又带淫゛_ 提交于 2019-12-11 01:58:36
问题 I have an NSWindow which can be closed and reopened (I've called [setReleasedWhenClosed: NO] ). How do I check if it is open or closed programmatically? I've read the doc and Googled but can't see a sane way to do this. [isVisible] is deprecated. [occlusionState] isn't what I'm after. I've worked around it using notifications, but I can't believe there isn't some property or method on NSWindow to do this 回答1: You make make of use of screen property of NSWindow. If the window in offscreen it

NSControl isEnabled only available in OS X v10.0 through OS X v10.9

空扰寡人 提交于 2019-12-11 01:54:58
问题 Does anybody know why NSControl's isEnabled has been removed while setEnabled: is still working? 回答1: In OS X 10.10 (and iOS 8), many of the getter/setter method pairs in Apple's frameworks were replaced by @property declarations. This both makes the header interface clearer and makes the import of those APIs into Swift more... well, Swifty. // Before - (BOOL)isEnabled; - (void)setEnabled:(BOOL)enabled; // After @property(getter=isEnabled) BOOL enabled The documentation hasn't been fully

NSLayoutManager hides new line characters no matter what I do

大城市里の小女人 提交于 2019-12-11 00:52:42
问题 I'm trying to show invisible characters like the new line character in my NSTextView subclass. The usual approach like overriding drawGlyph method of NSLayoutManager is a bad idea because it's too slow and not work properly with multi-paged layout. What I'm trying to do is to override the setGlyph method of the NSLayoutManager so it would replace invisible "\n" glyph with "¶" glyph and " " with "∙". And it works on the " " space glyphs but has no effect on the new line characters. public

`ImportError: No module named AppKit` after installing AppKit and PyObjC

淺唱寂寞╮ 提交于 2019-12-10 19:33:35
问题 I'm trying to get some Python code working on a fresh installation on Anaconda on Mac OS X Mojave with Python 2.7. This was all stuff that was working before on the same machine. The error I'm getting is this: Mac:~ kuzzooroo$ python Python 2.7.15 |Anaconda, Inc.| (default, Dec 14 2018, 13:10:39) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import AppKit Traceback (most recent call last): File

CoreText font smoothing on a transparent background

空扰寡人 提交于 2019-12-10 15:07:50
问题 I'm trying to render using CoreText (appkit version) on a (semi-) transparent background, and as a result the edges aren't smooth. Searching the web suggests that there's no solution to this problem, however I don't believe it because of one simple observation: if I create a CATextLayer containing the same string then the font is lovely and smooth. I've tried setting the various 'allowed' settings to true and then working through the 16 possibilities that they offer. Some are better than

Why does the blinking cursor in textfield cause drawRect to be called?

那年仲夏 提交于 2019-12-10 15:07:45
问题 I have the following view hierarchy setup in my program. Window +ContentView (Subview of Window) ++MyCustomView (Subview of ContentView) ++MyCustomOpaqueView (Subview of ContentView) +++TextField (Subview of MyCustomOpaqueView) When the user clicks the TextField the cursor inside of it starts to blink. On each blink drawRect is called on MyCustomView. Not a big deal, but I'm wondering why? In MyCustomOpaqueView I implement isOpaque like so, - (BOOL)isOpaque {return YES;} I thought this would

Add lots of views to NSScrollView

北慕城南 提交于 2019-12-10 10:59:07
问题 I'm trying to add one subview (view from an NSViewController ) for every element in a dictionary to a NSScrollView to get kind of a tableview, but with much more flexibility over the cells. Is it possible to place (programmatically) e.g. 100 subviews underneath each other so that you have to scroll down the NSScrollView to get to the last element??? Thanks in advanced, Grolior 回答1: The short answer is yes. I have done this before, and I assure you that it will work. Let me also assure you

How to Color the “Overshoot” Background of an NSCollectionView

十年热恋 提交于 2019-12-10 10:07:34
问题 I have implemented a collection view on my Cocoa app following Ray Wenderlich's tutorial (very helpful, given how buggy and broken Apple's API is in this area). In the tutorial, the collection view's canvas is colored black using the following code (all code is in view controller class' viewDidLoad() method): collectionView.layer?.backgroundColor = NSColor.black.cgColor However, the area that "peeks" when you overshoot ("rubber-band") the scroll using -for example- a magic mouse/scrollwheel,

Autorelease pools in appkit applications

六月ゝ 毕业季﹏ 提交于 2019-12-10 00:36:30
问题 I'm having difficulties to understand exactly WHEN autorelease pools are created and released in AppKit apps. For example, if I have an ApplicationController class that overrides init, is there an autorelease pool that gets created before it starts and gets drained after it ends? 回答1: The main thread in an AppKit application runs an NSRunLoop to process events. NSRunLoop creates a new autorelease pool every time it processes a new event (or timer) and drains it once control flow has returned

NSNumberFormatter doesn't allow typing decimal numbers

混江龙づ霸主 提交于 2019-12-08 15:59:00
问题 I am totally bewildered using NSNumberFormatter. This should be totally simple but I can't get it to work. I'd like to set an NSTextField to allow typing decimal numbers, either with a decimal point or without. Here is what I'd think would work: NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterDecimalStyle]; [formatter setMinimumFractionDigits:0]; [formatter setMaximumFractionDigits:4]; [formatter setAllowsFloats:YES]; [