【问题标题】:Adding an NSProgressIndicator to the dock icon将 NSProgressIndicator 添加到停靠图标
【发布时间】:2011-04-29 15:06:47
【问题描述】:

我正在创建一个应在停靠图标中显示进度条的应用程序。目前我有这个,但它不工作:

  NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 10.0f, 20.0f)];
  [progressIndicator setStyle:NSProgressIndicatorBarStyle];
  [progressIndicator setIndeterminate:NO];
  [[[[NSApplication sharedApplication] dockTile] contentView] addSubview:progressIndicator];
  [progressIndicator release];

或者我必须自己在码头上画出来吗?谁能帮我?谢谢。

【问题讨论】:

    标签: cocoa nsview dock nsprogressindicator nsdocktile


    【解决方案1】:

    最后我不得不使用以下代码,因为 contentView 为空:

        docTile = [[NSApplication sharedApplication] dockTile];
        NSImageView *iv = [[NSImageView alloc] init];
        [iv setImage:[[NSApplication sharedApplication] applicationIconImage]];
        [docTile setContentView:iv];
    
        progressIndicator = [[NSProgressIndicator alloc]
                                                  initWithFrame:NSMakeRect(0.0f, 0.0f, docTile.size.width, 10.)];
        [progressIndicator setStyle:NSProgressIndicatorBarStyle];
        [progressIndicator setIndeterminate:NO];
        [iv addSubview:progressIndicator];
    
        [progressIndicator setBezeled:YES];
        [progressIndicator setMinValue:0];
        [progressIndicator setMaxValue:1];
        [progressIndicator release];
    
        [self setProgress:[NSNumber numberWithFloat:-1]];
    }
    
    - (void)setProgress:(NSNumber *)fraction {
        if ( [fraction doubleValue] >= 0 ) {
            [progressIndicator setDoubleValue:[fraction doubleValue]];
            [progressIndicator setHidden:NO];
        }
        else
            [progressIndicator setHidden:YES];
        [docTile display];
    }
    

    【讨论】:

      【解决方案2】:

      刚刚试用了 DockTile 示例代码:http://developer.apple.com/library/mac/#samplecode/DockTile/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004391

      我设法通过添加让 NSProgress 栏显示在那里

      NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, 100.0f, 20.0f)];
      [self addSubview:progressIndicator];
      [progressIndicator setStyle:NSProgressIndicatorBarStyle];
      [progressIndicator setIndeterminate:NO];
      [progressIndicator setMinValue:0];
      [progressIndicator setMaxValue:100];
      [progressIndicator setDoubleValue:25];
      [progressIndicator release];
      

      到 initWithFrame 中的 SpeedometerView.m,但它在 Dock 中仍然是灰色的。

      我还发现了这个页面:http://osx.hyperjeff.net/Apps/apps?p=4&sub=22&l=1&u=on,其中有“PMProgressIndicator”,这可能会有所帮助,但我没有深入了解它。

      希望对你有所帮助,如果你弄明白了,请在此处发帖,我也有兴趣知道。

      【讨论】:

      • 我发现每次进度条发生变化时我都需要重新显示停靠栏的视图。 (:
      • 你的栏是灰色的吗?当我快速开始时,它总是对我来说是灰色的......
      猜你喜欢
      • 1970-01-01
      • 2011-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-07
      • 1970-01-01
      • 1970-01-01
      • 2014-08-16
      相关资源
      最近更新 更多