【问题标题】:NSWindow with very huge usage of CPU over 120% while openingNSWindow 打开时 CPU 使用率超过 120%
【发布时间】:2015-03-31 18:53:25
【问题描述】:

我正在使用https://github.com/obolton/OBMenuBarWindow 创建我的应用程序并面临性能问题。当我通过单击 NSStatusItem 打开我的NSWindow : OBMenuBarWindow 时,没有问题。但是当我再次单击它关闭窗口时,CPU 使用率确实开始快速增加(超过 120%)。再次打开窗口,CPU使用率会正常(0%)。这些每次都会在打开和关闭窗口时发生。我也尝试使用 Instruments 进行调试,但无法解决此问题。我的编码出了什么问题?这是我的代码 sn-p:

@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

【问题讨论】:

    标签: objective-c cocoa instruments cpu-usage nswindow


    【解决方案1】:

    您可以尝试使用 NSWindow 而不是 OBMenuBarWindow 做同样的事情。所以你可以找出它是一个NSWindow问题或OBMenuBarWindow中的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-22
      • 1970-01-01
      • 2023-03-21
      • 2017-09-12
      • 2014-03-14
      • 2014-09-11
      • 1970-01-01
      相关资源
      最近更新 更多