Skip to content

Instantly share code, notes, and snippets.

@monyschuk
Created February 8, 2022 01:26
Show Gist options
  • Save monyschuk/5e5321c30aa06d319106d7ae3b4a2f1e to your computer and use it in GitHub Desktop.
Save monyschuk/5e5321c30aa06d319106d7ae3b4a2f1e to your computer and use it in GitHub Desktop.
disables all animation of NSPopover (for use in SwiftUI apps where there is no control over popover display animation
//
// NSPopover_OverrideAnimation.h
// scrl (macOS)
//
// Created by Mark Onyschuk on 2022-02-07.
//
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSPopover (NSPopover_Override)
@end
NS_ASSUME_NONNULL_END
//
// NSPopover_OverrideAnimation.m
// scrl (macOS)
//
// Created by Mark Onyschuk on 2022-02-07.
//
#import "NSPopover_OverrideAnimation.h"
#import <objc/runtime.h>
@implementation NSPopover (NSPopover_OverrideAnimation)
+ (void)load {
Method mold = class_getInstanceMethod(self, @selector(animates));
Method mnew = class_getInstanceMethod(self, @selector(swizzled_animates));
if (mold != nil && mnew != nil) {
method_exchangeImplementations(mold, mnew);
}
}
- (BOOL)swizzled_animates {
return NO;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment