ما الذي يسبب تطبيق الحدود البيضاء على nsprogressIndicator المعروضة في قائمة النظام؟
-
01-10-2019 - |
سؤال
هذا ما يحدث عندما أقوم بإنشاء nsprogressIndicator و استعمال NSStatusItem
'س -setView:
طريقة لعرضها في منطقة مينوبار أثناء أداء إجراء:
مثال على عابث nsprogressIndicator http://cl.ly/l9r/content
ما الذي يسبب عرض هذه الحدود ، وكيف يمكنني إزالته؟ والنتيجة المقصودة هي أن يكون التحكم شفافًا.
هذا هو الرمز الذي أستخدمه:
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] init];
[progressIndicator setBezeled: NO];
[progressIndicator setStyle: NSProgressIndicatorSpinningStyle];
[progressIndicator setControlSize: NSSmallControlSize];
[progressIndicator sizeToFit];
[progressIndicator startAnimation: self];
[statusItem setView: progressIndicator]; // statusItem is an NSStatusItem instance
...
[statusItem setView: nil];
[progressIndicator stopAnimation: self];
[progressIndicator release];
المحلول
لا تقم بتقييم NSProgressIndicator
على الرغم من أنها أيضًا NSView
. قم بإنشاء طريقة عرض جديدة يتم تغيير حجمها بشكل جيد ، ضع مؤشر الحالة في هذا العرض ، وتمرير العرض المرفق إلى -[NSStatusItem setView:]
. ها هو تنفيذي.
في NSStatusItem+AnimatedProgressIndicator.m
,
- (void) startAnimation {
NSView *progressIndicatorHolder = [[NSView alloc] init];
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] init];
[progressIndicator setBezeled: NO];
[progressIndicator setStyle: NSProgressIndicatorSpinningStyle];
[progressIndicator setControlSize: NSSmallControlSize];
[progressIndicator sizeToFit];
[progressIndicator setUsesThreadedAnimation:YES];
[progressIndicatorHolder addSubview:progressIndicator];
[progressIndicator startAnimation:self];
[self setView:progressIndicatorHolder];
[progressIndicator center];
[progressIndicator setNextResponder:progressIndicatorHolder];
[progressIndicatorHolder setNextResponder:self];
}
- (void) stopAnimation {
[self setView:nil];
}
- (void) mouseDown:(NSEvent *) theEvent {
[self popUpStatusItemMenu:[self menu]];
}
- (void) rightMouseUp:(NSEvent *) theEvent {}
- (void) mouseUp:(NSEvent *) theEvent {}
…
أضفت طريقة مخصصة ، -[NSView center]
, ، وهو ما يلي:
@implementation NSView (Centering)
- (void) center {
if (![self superview]) return;
[self setFrame:NSMakeRect(
0.5 * ([self superview].frame.size.width - self.frame.size.width),
0.5 * ([self superview].frame.size.height - self.frame.size.height),
self.frame.size.width,
self.frame.size.height
)];
}
@end
نصائح أخرى
لقد رأيت أنك حلت المشكلة ، سأترك هذا بديلاً لتنفيذك. يمكنك استخدام تقدم.
لا تنتمي إلى StackOverflow