appkit

Layer backed NSView with custom CALayer not calling updateLayer?

柔情痞子 提交于 2020-06-10 02:41:37
问题 I have a custom layer-backed NSView and have overidden the makeBackingLayer method to return a custom CALayer subclass. I have also overriden wantsUpdateLayer to return true thereby fully opting into layer-like drawing. override func makeBackingLayer() -> CALayer { return Layer() // my custom class with "drawLayer:" implemented } override var wantsUpdateLayer:Bool{ return true } // never called override func updateLayer() { super.updateLayer() println("updateLayer after") self.layer?

Layer backed NSView with custom CALayer not calling updateLayer?

独自空忆成欢 提交于 2020-06-10 02:41:28
问题 I have a custom layer-backed NSView and have overidden the makeBackingLayer method to return a custom CALayer subclass. I have also overriden wantsUpdateLayer to return true thereby fully opting into layer-like drawing. override func makeBackingLayer() -> CALayer { return Layer() // my custom class with "drawLayer:" implemented } override var wantsUpdateLayer:Bool{ return true } // never called override func updateLayer() { super.updateLayer() println("updateLayer after") self.layer?

How to put SwiftUI button into NSToolbar?

为君一笑 提交于 2020-05-13 03:46:41
问题 This is how SwiftUI can be inserted into NSToolbar using an accessory view controller: import SwiftUI import PlaygroundSupport var hostingView = NSHostingView(rootView: ZStack { Color.clear HStack { Text("Hey") Text("SwiftUI") } } .padding() .edgesIgnoringSafeArea(.all) ) hostingView.frame.size = hostingView.fittingSize let titlebarAccessory = NSTitlebarAccessoryViewController() titlebarAccessory.view = hostingView titlebarAccessory.layoutAttribute = .trailing let mask: NSWindow.StyleMask = [

Show NSMenu only on NSStatusBarButton right click?

江枫思渺然 提交于 2020-03-16 07:15:31
问题 I have the following code: (can be copy-pasted to New macOS project) import Cocoa import SwiftUI @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { var statusBarItem: NSStatusItem! func applicationDidFinishLaunching(_ aNotification: Notification) { let statusBar = NSStatusBar.system statusBarItem = statusBar.statusItem( withLength: NSStatusItem.squareLength) statusBarItem.button?.title = "🍎" // Setting action statusBarItem.button?.action = #selector(self

Purpose of CALayer?

允我心安 提交于 2020-02-04 02:40:48
问题 I'm slightly used as to what the purpose of CALayer's existence is. Why not just put the properties in a UIView? Thanks. 回答1: A CALayer represents a completely different "thing" from a UIView. A CALayer only deals with drawing itself, and encapsulating the information needed to do that. A view, on the other hand, owns one or many layers, which it uses to draw itself. A view has many other functions and properties though, that are unrelated to its representation on the screen. I would

Visual guide of AppKit controls?

岁酱吖の 提交于 2020-01-13 18:12:08
问题 Is there a visual guide to the controls in Mac OS/X AppKit? Take, for instance, the following control that appears at different places in XCode UI: I don't know which AppKit control is that. Any ideas? 回答1: It looks like a series of NSRadioButton views in an NSMatrix . You can determine the former using Accessibility Inspector, which will tell you that these buttons are of the accessibility class AXRadioButton . You can determine the latter using f-script. (You'll need the new 10.7 injection

NSResponder chain being broken after i remove / insert views

烂漫一生 提交于 2020-01-07 03:07:22
问题 It appears that when i remove subviews from my NSViewController main view, responder chain gets modified and new views never receive the first responder. View controller is inside popover. There is search field on top, and custom views below (search results). When i show popover i can use tab to go to the custom views. But if i search for some phrase search results are changed and tab no longer works. Any idea if there is way to 'fix' the responder chain ? 回答1: Answer from Mike Abdullah

Cocoa: distinguish input device / scrollWheel: as mouse-scroll wheel and TrackPad

我是研究僧i 提交于 2020-01-05 04:31:12
问题 I am looking for a method to reliably distinguish within [NSResponder scrollWheel:] if the users input device has a one-dimensional scroll-wheel or a two dimensional trackPad/magicMouse? In the first I would like to implement a different behavior. But just taking a look on the deltaX of the NSEvent would be a little weak. Any suggestions? 回答1: You can use the private method call [theEvent _scrollPhase] to tell whether the device is using inertial scrolling, which indicates an Apple-supplied