Skip to content

Instantly share code, notes, and snippets.

@OhItsShaun
OhItsShaun / NSToolbarItem+UIPopoverPosition.swift
Last active May 16, 2023 04:00
Position UIPopover from NSToolbarItem
// You may want to present a UIKit popover from an NSToolbarItem, e.g. Maps.app uses
// a popover to select between viewing modes of default, Transit and Satlite.
//
// In UIKit land, set the popover controller's source view as the containing UIWindow,
// and use the following to grab the source rect from the NSToolbarItem in an AppKit
// bundle.
//
// Uses private APIs so mileage varies.
func position(for toolbarItem: NSToolbarItem) -> CGRect? {
guard let view = toolbarItem.value(forKey: "_view") as? NSView,
@OhItsShaun
OhItsShaun / ObserveUINSWindow.swift
Created March 29, 2020 18:24
Observing window key changes in Marzipan
import UIKit
extension NSNotification.Name {
static let didResignKey = Self.init("UISBHSMainHostWindowDidResignKeyNotification")
static let didBecomeKey = Self.init("UISBHSMainHostWindowDidBecomeKeyNotification")
}
extension Notification {

Keybase proof

I hereby claim:

  • I am ohitsshaun on github.
  • I am shaunamerchant (https://keybase.io/shaunamerchant) on keybase.
  • I have a public key whose fingerprint is F550 610A C16A 919D 209A 4C87 D5C1 BE20 A58A 640A

To claim this, I am signing this object: