gpt4 book ai didi

objective-c - 在 Cocoa 中使用 NSTimer 关闭自定义 NSPanel

转载 作者:行者123 更新时间:2023-12-03 17:40:08 27 4
gpt4 key购买 nike

我创建了自定义 NSPanel 并用 Sheet 开始展示它。它上面没有任何关闭按钮,我想在 10 秒后用 NSTimer 关闭这个面板。我怎样才能做到这一点?

[[NSApplication sharedApplication] beginSheet: scanningPanel
modalForWindow: window
modalDelegate: self
didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo: nil];

[[NSApplication sharedApplication] runModalForWindow: scanningPanel];
NSTimer *myTimer = [NSTimer timerWithTimeInterval: 10.0
target:self
selector: @selector(closePanel:) userInfo:nil
repeats:NO];

[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSModalPanelRunLoopMode];

closePanel()函数:

-(void) closePanel: (NSTimer *) theTimer
{
NSLog(@"closePanel");
[scanningPanel abortModal]; // seems it not work
}

最佳答案

试试这个:

[NSApp beginSheet:scanningPanel modalForWindow:[self window]
modalDelegate:self
didEndSelector:nil
contextInfo:self];

NSTimer *tm=[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(closePanel:)
userInfo:nil
repeats:NO];

- (void)closePanel:(NSTimer *)theTimer
{
NSLog(@"closePanel");
[NSApp endSheet:scanningPanel];
[scanningPanel orderOut:self];
}

关于objective-c - 在 Cocoa 中使用 NSTimer 关闭自定义 NSPanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18502229/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com