我使用https://github.com/obolton/OBMenuBarWindow创建应用程序并遇到性能问题。当我通过单击NSStatusItem打开我的NSWindow : OBMenuBarWindow
时,没有问题。但是当我再次点击它以关闭窗口时,CPU使用率确实开始快速增加(超过120%)。再次打开窗口,CPU使用率将正常(0%)。这些都是在打开和关闭窗口时发生的。我也尝试使用Instruments进行调试,但无法解决此问题。我的编码出了什么问题?这是我的代码片段:
@interface MainWindowController : NSWindowController
@property (nonatomic, assign) CGFloat arrowWidth;
@property (nonatomic, assign) CGFloat arrowHeight;
@property (nonatomic) IBOutlet TableController *tableController;
@property IBOutlet OBMenuBarWindow *window;
@end
@implementation MainWindowController
- (void)windowDidLoad {
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
self.window.menuBarIcon = [NSImage imageNamed:@"paperclipblack"];
self.window.highlightedMenuBarIcon = [NSImage imageNamed:@"paperclipwhite"];
self.window.title = @"App";
self.window.hasMenuBarIcon = YES;
self.window.attachedToMenuBar = YES;
self.window.isDetachable = YES;
self.arrowWidth = 20;
self.arrowHeight = 10;
}
- (void)setArrowWidth:(CGFloat)width {
self.window.arrowSize = NSMakeSize(width, self.window.arrowSize.height);
}
- (void)setArrowHeight:(CGFloat)height {
self.window.arrowSize = NSMakeSize(self.window.arrowSize.width, height);
}
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (strong) MainWindowController *mainWindowController;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
_mainWindowController = [[MainWindowController alloc] initWithWindowNibName:@"MainWindowController"];
[_mainWindowController showWindow:nil];
}
@end
答案 0 :(得分:0)
您可以尝试使用NSWindow而不是OBMenuBarWindow。因此,您可以在OBMenuBarWindow中找出它的NSWindow问题或问题。