ios - Apple Watch 圆形进度(或径向弧形进度),图像错误

标签 ios objective-c iphone apple-watch

我正在使用 WatchKit 为 Apple Watch 开发一个应用程序,我需要在录制音频时实现循环进度,类似于 Apple 演示。

我不知道 WatchKit 是否包含默认执行此操作的功能,因此我创建了自己的图像(13 个图像,持续 12 秒[总共 209 KB]),并使用计时器进行更改。

这是我的源代码:

开始/停止录制的按钮操作

- (IBAction)recordAction {
   NSLogPageSize();
   NSLog(@"Recording...");

   if (!isRecording) {
      NSLog(@"Start!");
      isRecording = YES;

      _timerStop = [NSTimer scheduledTimerWithTimeInterval:12.0
                                                  target:self
                                                selector:@selector(timerDone)
                                                userInfo:nil
                                                 repeats:NO];

      _timerProgress = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                      target:self
                                                    selector:@selector(progressChange)
                                                    userInfo:nil
                                                     repeats:YES];
   } else {
       NSLog(@"Stop :(");
       [self timerDone];
   }

}

计时器结束或再次点击按钮时执行的操作

-(void) timerDone{
   NSLog(@"timerDone");
   [_timerProgress invalidate];
   _timerProgress = nil;
   [recordButtonBackground setBackgroundImageNamed:[NSString stringWithFormat:@"ic_playing_elipse_12_%d", 12]];
   counter = 0;
   isRecording = NO;
 }

更改进度的方法

- (void)progressChange
{
  counter++;
   NSLog(@"%d", counter);
   NSString *image = [NSString stringWithFormat:@"ic_playing_elipse_12_%d", counter];
   [recordButtonBackground setBackgroundImageNamed:image];
   NSLog(image);
}

这是一个显示错误的 gif。它开始显示,但随机更改图像,直到几秒钟。 (注意:我已经检查过第一张图像是否有正确的进度)

Screen recording that shows my bug

更新(其他解决方案):使用 startAnimating

有一种新方法可以使用 startAnimatingWithImagesInRange:duration:repeatCount 来显示循环进度

您需要指定动画的图像范围和持续时间。请参阅下面的示例:

[self.myElement startAnimatingWithImagesInRange:NSMakeRange(0, 360) duration:myDuration repeatCount:1];

最佳答案

我相信这是 WatchKit 解释图像名称方式的副作用。

以数字结尾的图像名称用于表示动画图像中的帧,因此“ic_playing_elipse_12_10”被解释为名为“ic_playing_eclipse_12_1”的图像的第一帧,并且当您希望它显示第一个图像时,将显示第 10 个图像一个。

您应该能够只更改图像名称,这样数字就不是图像名称的最后一部分,它会修复它。

关于ios - Apple Watch 圆形进度(或径向弧形进度),图像错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29284104/

相关文章:

ios - UIImagePickerController 在 iOS 9 上不请求权限

iphone - UISwipeGestureRecognizer 在 iOS 4.3 中不起作用

ios - 如何访问DJIGO App飞行计划日志文件

iOS Sprite Kit SKShapeNode 不填满整个路径

ios - 如何实现与 CBPeripheral 的安全连接?

objective-c - CGPoint 的 NSPredicate 过滤器类

ios - UIView 显示了 25%

objective-c - 转换为 (id) 以调用 Objective-C 中的任意方法

iphone - 如何将 NSNumber 转换和比较为 BOOL?

iphone - UIFont 类别的单元测试用例编写问题