appkit

NSScrollView how to start from top left corner

痴心易碎 提交于 2021-02-10 08:43:07
问题 How to set scrollView document view to be pinned to top left corner? If scrollView is big enough/bigger than its content, everything is drawn from bottom to up and it not looks right. I have to override isFlipped of scrollView? I was searching internet and overriding isFlipped to return true is not everything. I don't want to make my documentView flipped because then I have to make changes in that class to make everything looks like I want. 回答1: I created simple NSView class as an container

Is drawing to an MTKView or CAMetalLayer required to take place on the main thread?

笑着哭i 提交于 2021-02-07 04:17:01
问题 It's well known that updating the user interface in AppKit or UIKit is required to take place on the main thread. Does Metal have the same requirement when it comes to presenting a drawable ? In a layer-hosted NSView that I've been playing around with, I've noticed that I can call [CAMetalLayer nextDrawable] from a dispatch_queue that is not the main_queue . I can then update that drawable's texture as usual and present it. This appears to work properly, but I find that rather suspicious.

Is drawing to an MTKView or CAMetalLayer required to take place on the main thread?

ぐ巨炮叔叔 提交于 2021-02-07 04:16:24
问题 It's well known that updating the user interface in AppKit or UIKit is required to take place on the main thread. Does Metal have the same requirement when it comes to presenting a drawable ? In a layer-hosted NSView that I've been playing around with, I've noticed that I can call [CAMetalLayer nextDrawable] from a dispatch_queue that is not the main_queue . I can then update that drawable's texture as usual and present it. This appears to work properly, but I find that rather suspicious.

Import Error: No module named AppKit

人走茶凉 提交于 2021-02-04 17:13:27
问题 I use Mac OS X Lion and Python 2.7 . I am new to python. Can anyone tell me how to import AppKit and PyObjC to Python . But i get the errors when trying to import Import Error: No module named AppKit or ' Import Error: No module named PyObjC . Trying easy_install does not help either. What can i do to import these 2 modules? 回答1: If not already installed, install pip by running: sudo easy_install pip Then run: ## install for all users sudo pip install pyobjc or ## install for current user

NSViewControllerRepresentable not responding to events when embedded into SwiftUI List

吃可爱长大的小学妹 提交于 2021-01-29 18:24:54
问题 I have the following code snippets: The list element: struct PaletteListRowUIView: View { @State var colorPalette: ColorPalette var isSelected: Bool var onSelect: () -> Void var body: some View { return VStack(alignment: .leading) { HStack { Group { if(isSelected) { Ellipse().fill(Color.white) } else { Ellipse().stroke(Color.white) } }.contentShape(Ellipse()) .aspectRatio(1, contentMode: .fit).frame(width: 10, height: 10) .gesture(TapGesture().onEnded(onSelect)) RenameableText(text:

NSMenuItem with custom view disappears while scrolling

五迷三道 提交于 2021-01-29 07:27:11
问题 I implement a NSMenu with NSMenuItem and set custom view to it. When menu is scrollable, mouse hovering on ▼ button to scroll will cause some menuItem disappear (or not draw correctly). Hope someone give me some help. I will appreciate that. Here's video about this issue: https://streamable.com/obrbon Here's my code: private func setupMenuItemView(_ menu: NSMenu) { let menuItemHeight: CGFloat = 20 let menuWidth = frame.width let textFieldPadding: CGFloat = 10 for menuItem in menu.items {

First responder on mouse down behavior NSControl and NSView

巧了我就是萌 提交于 2021-01-28 13:57:08
问题 I have a custom control. If it inherits from NSView , it automatically becomes the first responder when I click on it. If it inherits from NSControl , it does not. This difference in behavior persists, even if I override mouseDown(with:) and don't call super. Code: class MyControl: NSView { override var canBecomeKeyView: Bool { return true } override var acceptsFirstResponder: Bool { return true } override func drawFocusRingMask() { bounds.fill() } override var focusRingMaskBounds: NSRect {

NSMenuItem with attributedTitle containing an NSFont object draws the title with baseline shift

最后都变了- 提交于 2021-01-27 19:31:06
问题 I'm tying to create an NSPopUpButton with the list of fonts available in the system. Seemed pretty obvious task but I've failed. I guess, I'm missing something so obvious that I've completely forgot about it. The code is pretty straight: let button = NSPopUpButton() button.menu = NSMenu() NSFontManager.shared.availableFonts.forEach { fontNameString in let item = NSMenuItem() let font = NSFont(name: fontNameString, size: 14)! let attrs: [NSAttributedString.Key: Any] = [.font: font] item

How to collapse an NSSplitView pane with animation while using Auto Layout?

僤鯓⒐⒋嵵緔 提交于 2021-01-21 07:27:26
问题 I've tried everything I can think of, including all the suggestions I've found here on SO and on other mailing lists, but I cannot figure out how to programmatically collapse an NSSplitView pane with an animation while Auto Layout is on. Here's what I have right now (written in Swift for fun), but it falls down in multiple ways: @IBAction func toggleSourceList(sender: AnyObject?) { let isOpen = !splitView.isSubviewCollapsed(sourceList.view.superview!) let position = (isOpen ? 0 : self

SwiftUI: Detect finger position on Mac trackpad

前提是你 提交于 2021-01-20 20:10:03
问题 I'm making a SwiftUI app for macOS and I'd like to use the trackpad as an (x, y) input by detecting the position of the user's fingers. I wanna be able to detect multiple fingers that are resting on the trackpad (not dragging). How do I do that? A similar question has been asked before, but I'm asking again because that was from nearly 10 years ago, the answers are all in Obj-C (one in Swift 3), and I'm wondering if there's an updated methodology. Most importantly, I've no clue how to