当我在执行动作时创建NSProgressIndicator并使用NSStatusItem's -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];
Run Code Online (Sandbox Code Playgroud) 我想创建一个带有嵌入的菜单项NSProgressIndicator,类似于 Wi-Fi 状态菜单的“Wi-Fi:寻找网络...”菜单项:

我认为我将需要使用如下所述的setView:方法:菜单项中的视图。但是,当我调用setView:并传递 时NSProgressIndicator,只NSProgressIndicator显示 。
如何创建自定义菜单项视图以获得与 Wi-Fi 状态菜单的“Wi-Fi:寻找网络...”菜单项类似的结果?
我在我的主线程中使用NSProgressIndicator来更新进度,因为我运行了整个方法.现在,当我最终从另一个类文件调用一个对象,并等待该对象返回到我的主线程的值时,我注意到NSProgressIndicator将消失.我知道这是因为主线程被阻塞,直到我从另一个对象获得返回值.
所以我的问题是在主线程中更新UI而不阻塞它并让其他对象在后台运行并根据需要将值返回给主线程的推荐方法是什么.我知道如何使用块,但不允许块操作返回值.我需要的是帮助这个伪代码的东西:
-(IBAction) main {
//Update progress indicator UI to show progress
//perform an call to another object from another class.
// wait till i get its return value.
//Update progress indicator UI to show progress
// Use this return value to do something.
//Update progress indicator UI to show progress
}
Run Code Online (Sandbox Code Playgroud)
当调用另一个对象时,我注意到确定的NSProgressIndicator我已经完全消失,因为主线程被阻塞了.谢谢.
我想用线程更新进度条,如此处所述.我正在努力实现这个结果:
这是我的代码:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
progressBar.hidden = NO;
for (NSInteger i = 1; i <= progressBar.maxValue; i += 20){
[NSThread sleepForTimeInterval:1.0];
dispatch_async(dispatch_get_main_queue(), ^{
[progressBar setDoubleValue:(double)i];
[progressBar displayIfNeeded];
});
}
progressBar.hidden = YES;
});
Run Code Online (Sandbox Code Playgroud)
进度条在我的ViewController.h中以这种方式定义:
NSProgressIndicator *progressBar
问题是在循环结束时没有删除条形,我不知道是否以progressBar.hidden = YES;这种方式工作.
有人能帮我吗?代码片段非常有用,特别是如果后面有解释的话.
我怎样才能使用NSLevelIndicator?我对此非常陌生,所以我对如何在我的应用程序中使用进度条知之甚少.
cocoa appkit nsprogressindicator nslevelindicator progress-bar
我的应用程序使用一堆For循环做了很多工作.它会计算大量的字符串,并且可能需要一整分钟才能完成.
所以我在我的应用程序中放置了一个NSProgressIndicator.
在循环中,我使用了NSProgressIndicator的"incrementBy"函数.但是,我没有看到实际的酒吧填满.
我怀疑这是因为循环使所有功能成为可能,因此NSProgressIndicator没有更新(图形化).
那我怎么能取得进展呢?
我想更改在NSProgressIndicator栏内绘制的默认渐变的颜色.什么是最简单的方法?
我在我的应用程序中遵循以下周期
var maxIterations: Int = 0
func calculatePoint(cn: Complex) -> Int {
let threshold: Double = 2
var z: Complex = .init(re: 0, im: 0)
var z2: Complex = .init(re: 0, im: 0)
var iteration: Int = 0
repeat {
z2 = self.pow2ForComplex(cn: z)
z.re = z2.re + cn.re
z.im = z2.im + cn.im
iteration += 1
} while self.absForComplex(cn: z) <= threshold && iteration < self.maxIterations
return iteration
}
Run Code Online (Sandbox Code Playgroud)
并在循环执行期间显示彩虹轮。如何管理该应用仍在响应UI操作?注意:在循环运行时,我在代码的不同部分更新了NSProgressIndicator,该代码未更新(未显示进度)。我怀疑这与调度有关,但是我对此相当“绿色”。我非常感谢您的帮助。谢谢。
我尝试使用以下方法设置我自己的 NSProgressIndicator。
class ProgressViewController : NSViewController
{
override func loadView()
{
let view = NSView(frame: NSMakeRect(0,0,300,120))
view.wantsLayer = true
view.layer?.borderWidth = 0
self.view = view
let text = NSTextField(frame: NSRect(x: 20, y: 45, width: 260, height: 20))
text.drawsBackground = true
text.isBordered = false
text.backgroundColor = NSColor.controlColor
text.isEditable = false
self.view.addSubview(text)
text.stringValue = "Progress Text"
let indicator = NSProgressIndicator(frame: NSRect(x: 20, y: 20, width: 260, height: 20))
indicator.minValue = 0.0
indicator.maxValue = 100.0
indicator.doubleValue = 33.0
self.view.addSubview(indicator)
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是指标始终显示为满。我错过了一个技巧吗?
我有NSStatusItem与自定义NSView显示图像.无论菜单是否打开,它都会显示不同的图像:
isMenuVisible = NO;
- (void)awakeFromNib {
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem retain];
dragStatusView = [[DragStatusView alloc] init];
[dragStatusView retain];
dragStatusView.statusItem = statusItem;
[dragStatusView setMenu:statusMenu];
[dragStatusView setToolTip:NSLocalizedString(@"Menubar Countdown",
@"Status Item Tooltip")];
[statusItem setView:dragStatusView];
[dragStatusView setTitle:@"11"];
}
- (void)drawImage:(NSImage *)aImage centeredInRect:(NSRect)aRect{
NSRect imageRect = NSMakeRect((CGFloat)round(aRect.size.width*0.5f-aImage.size.width*0.5f),
(CGFloat)round(aRect.size.height*0.5f-aImage.size.height*0.5f),
aImage.size.width,
aImage.size.height);
[aImage drawInRect:imageRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
}
- (void)drawRect:(NSRect)rect {
// Draw status bar background, highlighted if menu is showing
[statusItem drawStatusBarBackgroundInRect:[self bounds]
withHighlight:isMenuVisible];
if(isMenuVisible) {
[self drawImage:image2 centeredInRect:rect];
}else {
[self drawImage:image1 …Run Code Online (Sandbox Code Playgroud) 我想在将文件从一个地方复制到另一个地方时使用进度条显示进度.所以这是复制文件的代码:
if([fileManager isReadableFileAtPath:sourcePath])
[fileManager copyItemAtPath:sourcePath toPath:destinationPath error:nil];
Run Code Online (Sandbox Code Playgroud)
以下是进度条的代码(我使用NSProgressIndicator):
// Set the max value to our source file size
[_localProgressIndicator setMaxValue:fileSizeTotal];
[_localProgressIndicator setDoubleValue:0.0];
//Start showing progress bar in using NSTime
if(!timerForProgressBar){
timerForProgressBar = [NSTimer scheduledTimerWithTimeInterval:0.05
target:self
selector:@selector(checkCopyingPorgress:)
userInfo:nil
repeats:YES];
[_localProgressIndicator startAnimation:self];
}
-(void)checkCopyingPorgress:(NSTimer *)aTimer
{
if(fileCurrentSize >= fileSizeTotal)
{
fileCurrentSize = 0;
[aTimer invalidate];
aTimer = NULL;
[_localProgressIndicator setDoubleValue:0.0];
[_localProgressIndicator stopAnimation: self];
}
else
{
[_localProgressIndicator setDoubleValue: fileCurrentSize/100.0];
[_localProgressIndicator displayIfNeeded];
}
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是当我将文件从一个地方复制到另一个地方时如何从fileManager获取"fileCurrentSize"?谢谢 !!
我参考以下示例-进度指示器 (在垂直布局中完成)在水平布局中制作了3个进度指示器:
<l:HorizontalLayout
class="sapUiContentPadding"
width="100%">
<l:content>
<ProgressIndicator
class="sapUiSmallMarginBottom"
percentValue="30"
displayValue="30%"
showValue="true"
width="28.7rem"
state="None" />
<ProgressIndicator
class="sapUiSmallMarginBottom"
percentValue="50"
showValue="false"
width="28.7rem"
state="Error" />
<ProgressIndicator
class="sapUiSmallMarginBottom"
percentValue="99"
displayValue="0.99GB of 1GB"
showValue="true"
width="28.7rem"
state="Success" />
</l:content>
</l:HorizontalLayout>
Run Code Online (Sandbox Code Playgroud)
为了使屏幕与我使用的3个指示器大小相等,width="28.7rem"但这可能不是正确的方法,并且也不响应(已知)
为了使它具有响应性,我读到我应该将整个东西包装在flex框中,所以我尝试如下操作:
<l:content>
<Panel class="sapUiDemoFlexBoxSizeAdjustments">
<FlexBox
alignItems="Start">
<items>
<ProgressIndicator
class="sapUiSmallMarginBottom"
percentValue="30"
displayValue="30%"
showValue="true"
width="100%"
state="None" />
<ProgressIndicator
class="sapUiSmallMarginBottom"
percentValue="50"
showValue="false"
width="100%"
state="Error" />
<ProgressIndicator
class="sapUiSmallMarginBottom"
percentValue="99"
displayValue="0.99GB of 1GB"
showValue="true"
width="100%"
state="Success" />
</items>
</FlexBox>
</Panel>
</l:content>
</l:HorizontalLayout>
Run Code Online (Sandbox Code Playgroud)
但这也没有帮助我(我想我的代码是错误的)。
我可以知道如何实现这些响应进度指标吗?
objective-c ×7
cocoa ×6
macos ×3
appkit ×1
ios ×1
menubar ×1
nsmenuitem ×1
nsstatusitem ×1
nsview ×1
progress-bar ×1
sapui5 ×1
swift ×1
swift3 ×1