使用xib而不是代码进行测试,就像魅力一样。 仍然认为应找到适当的解决方案和原因。 将继续根据需要进行更新
使用NSProgressIndicator创建一个popUp窗口,以显示通信过程的进展情况。
问题是progressIndicator不会更新。
检查并正常工作:
已检查且无法正常工作:
注意到行为:
在主应用程序窗口中测试了相同的代码并且运行良好。
如果我将alertPopUp窗口设为主,则不会有所作为。
我们非常欢迎您的想法,完全被阻止。
将向您显示alertPopUp代码和来电者:
@implementation XTAlertPopUp{
NSProgressIndicator *progressBar;
double incrementStep;
}
+ (XTAlertPopUp *)_baseInit:(NSView *)caller delegate:(id<XTAlertPopUpDelegate>)delegate{
CGRect viewPositionInScreen = [caller.window convertRectToScreen:[caller convertRect:caller.bounds toView:nil]];
XTAlertPopUp *alertPopUp = [[XTAlertPopUp alloc] initWithContentRect:CGRectMake(viewPositionInScreen.origin.x + ((caller.frame.size.width - windowWidth) * .5), viewPositionInScreen.origin.y + ((caller.frame.size.height - windowHeight) * .5), windowWidth, windowHeight)
styleMask:NSBorderlessWindowMask
backing: NSBackingStoreRetained
defer:YES];
alertPopUp.alertDelegate = delegate;
return alertPopUp;
}
+ (XTAlertPopUp *)alertProgressCalledFromView:(NSView *)caller withMessage:(NSString *)msg numberOfProgressStages:(NSUInteger)progressStages andCancelButtonTitle:(NSString *)cancelTitle settingDelegate:(id<XTAlertPopUpDelegate>)delegate{
XTAlertPopUp *alertPopUp = [XTAlertPopUp _baseInit:caller delegate:delegate];
NSBox *base = [alertPopUp _baseViewForAlert:msg cancelButton:cancelTitle];
[alertPopUp _buildProgressBarAndAddTo:base numberOfProgressStages:progressStages];
[alertPopUp setContentView:base];
[base release];
return alertPopUp;
}
- (void)dealloc{
[super dealloc];
[progressBar release];
}
#pragma mark --
#pragma mark UI
- (NSBox *)_baseViewForAlert:(NSString *)msg cancelButton:(NSString *)cancelTitle{
NSBox *base = [[NSBox alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[base setBoxType:NSBoxCustom];
[base setFillColor:[NSColor blackColor]];
[base setBorderColor:[NSColor orangeColor]];
[base setBorderWidth:2.0];
NSImageView *appIcon = [[NSImageView alloc] initWithFrame:CGRectMake(viewBorder, viewBorder, windowHeight - (viewBorder * 2), windowHeight - (viewBorder * 2))];
[appIcon setImage:[NSApp applicationIconImage]];
[base addSubview:appIcon];
NSTextField *text = [[NSTextField alloc] initWithFrame:CGRectMake(appIcon.frame.origin.x + appIcon.frame.size.width + viewBorder, (viewBorder * 2) + buttonSizeHeight, base.frame.size.width - (appIcon.frame.origin.x + appIcon.frame.size.width + (viewBorder * 3)), base.frame.size.height - ((viewBorder * 4) + buttonSizeHeight))];
[text.cell setStringValue:msg];
[text.cell setWraps:YES];
[text setEditable:NO];
[text setSelectable:NO];
[text.cell setBordered:NO];
[text.cell setBackgroundColor:[NSColor clearColor]];
[text setTextColor:[NSColor orangeColor]];
[base addSubview:text];
[base addSubview:[[self configureButton:CGRectMake(viewBorder, viewBorder, buttonsSizeWidth, buttonSizeHeight)
title:cancelTitle
tag:0] autorelease]];
[text release];
[appIcon release];
return base;
}
- (void)_buildProgressBarAndAddTo:(NSBox *)base numberOfProgressStages:(NSUInteger)progressStages{
progressBar = [[NSProgressIndicator alloc] initWithFrame:CGRectMake(viewBorder + (windowHeight - (viewBorder * 2)), viewBorder, base.frame.size.width - ((viewBorder * 2) + (windowHeight - (viewBorder * 2))), 50)];
[progressBar setIndeterminate:NO];
[progressBar setMinValue:0.0];
[progressBar setMaxValue:100.0];
[progressBar setDoubleValue:0.0];
[progressBar setStyle:NSProgressIndicatorBarStyle];
[progressBar setControlSize:NSRegularControlSize];
[progressBar setControlTint:NSGraphiteControlTint];
[progressBar setDisplayedWhenStopped:YES];
[base addSubview:progressBar];
incrementStep = 100.0 / progressStages;
}
- (NSButton *)configureButton:(CGRect)frame title:(NSString *)title tag:(NSUInteger)tag{
NSButton *btn = [[NSButton alloc] initWithFrame:frame];
[btn setTag:tag];
[btn setCell:[[[XTColorFrameButtonCell alloc] init] autorelease]];
[btn.cell setBezelStyle:NSRoundedBezelStyle];
[btn setBordered:YES];
[btn.cell setBordered:YES];
[btn setState:NO];
[[btn cell] setTitle:title];
[btn.cell setAction:@selector(buttonClicked:)];
[btn.cell setBackgroundColor:[NSColor clearColor]];
[btn.cell setFrameColor:[NSColor orangeColor]];
[btn.cell setButtonToPatchParams];
return btn;
}
- (void)incrementProgress{
if([progressBar doubleValue] >= 100.0)
[self killAlert];
[progressBar incrementBy:incrementStep];
NSLog(@"double >> %f", [progressBar doubleValue]);
NSLog(@"iskey >> %d || ismain >> %d", [self isKeyWindow], [self isMainWindow]);
[progressBar setNeedsDisplay:YES];
}
#pragma mark --
#pragma mark window override
- (BOOL)canBecomeKeyWindow{
return YES;
}
您可以使用它来调用测试:
- (void)testprogressBar{
[self alertPopUpSaveProgress:@(100)];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(increments:) userInfo:@(0) repeats:NO];
}
- (void)increments:(NSTimer *)timer{
NSNumber *inc = @([[timer userInfo] integerValue] + 1);
if([inc integerValue] > 99)
return;
NSLog(@"patch iskey >> %d || patch is main >> %d", [self.view.window isKeyWindow], [self.view.window isMainWindow]);
[alertProgress incrementProgress];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(increments:) userInfo:inc repeats:NO];
}
- (void)alertPopUpSaveProgress:(NSNumber *)numberOfSteps{
alertProgress = [XTAlertPopUp alertProgressCalledFromView:self.view
withMessage:@"Saving changes"
numberOfProgressStages:[numberOfSteps unsignedIntegerValue]
andCancelButtonTitle:@"cancel"
settingDelegate:self];
[alertProgress shootThreadedAlert];
}