OGeek|极客世界-中国程序员成长平台

标题: ios - 带有图像错误的 AppleWatch 圆形进度(或径向弧进度) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:49
标题: ios - 带有图像错误的 AppleWatch 圆形进度(或径向弧进度)

我正在使用 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
                                                selectorselector(timerDone)
                                                userInfo:nil
                                                 repeats:NO];

      _timerProgress = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                      target:self
                                                    selectorselector(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];



Best Answer-推荐答案


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

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

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

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4