Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift watchOS2 animateWithDuration启动缓慢且加速_Swift_Animation_Watchos 2 - Fatal编程技术网

Swift watchOS2 animateWithDuration启动缓慢且加速

Swift watchOS2 animateWithDuration启动缓慢且加速,swift,animation,watchos-2,Swift,Animation,Watchos 2,我试图通过调用WKInterfaceController类的animateWithDuration来设置watchOS2应用程序中组宽度的动画。其想法是向用户显示一条水平线,在一段时间内从右向左减小其宽度(类似计时器): 然而,我看到动画一开始,速度就非常慢,然后它就增加了。当动画即将停止时(当计时器宽度接近0时),动画将再次减速。 我希望在动画期间速度保持不变 以前有人有过这个问题吗?感谢您的帮助!感谢WatchOS 2没有提供指定计时功能的方法,因此动画仅限于使用EaseInEaseOut曲

我试图通过调用
WKInterfaceController
类的
animateWithDuration
来设置watchOS2应用程序中组宽度的动画。其想法是向用户显示一条水平线,在一段时间内从右向左减小其宽度(类似计时器):

然而,我看到动画一开始,速度就非常慢,然后它就增加了。当动画即将停止时(当计时器宽度接近0时),动画将再次减速。 我希望在动画期间速度保持不变


以前有人有过这个问题吗?感谢您的帮助!感谢WatchOS 2没有提供指定计时功能的方法,因此动画仅限于使用EaseInEaseOut曲线(该曲线开始缓慢,加速,最后减慢)


您可以尝试或使用一系列WKInterfaceImage帧平滑地设置线条的动画。

WatchOS 2没有提供指定计时功能的方法,因此动画仅限于使用EaseInEaseOut曲线(该曲线开始缓慢,加速,最后减慢)


你可以尝试,或者使用一系列WKInterfaceImage帧来平滑地制作线条动画。

我制作了一个简单的计时器示例,我想在watchOS2应用程序中使用核心图形制作动画。 你可以找到这个项目

更新: 以下是我编写的代码:

func configureTimerWithCounter(counter: Double) {

    let size = CGSizeMake(self.contentFrame.width, 6)
    UIGraphicsBeginImageContext(size)
    let context = UIGraphicsGetCurrentContext()
    UIGraphicsPushContext(context!)

    // Draw line
    let path = UIBezierPath()
    path.lineWidth = 100

    path.moveToPoint(CGPoint(x: 0, y: 0))

    let counterPosition = (self.contentFrame.width/30)*CGFloat(counter)
    path.addLineToPoint(CGPoint(x: counterPosition, y: 0))

    UIColor.greenColor().setStroke()
    UIColor.whiteColor().setFill()
    path.stroke()
    path.fill()

    // Convert to UIImage
    let cgimage = CGBitmapContextCreateImage(context);
    let uiimage = UIImage(CGImage: cgimage!)

    // End the graphics context
    UIGraphicsPopContext()
    UIGraphicsEndImageContext()

    self.timerImage.setImage(uiimage)

}

我制作了一个简单的计时器示例,我想在watchOS2应用程序中用核心图形制作动画。 你可以找到这个项目

更新: 以下是我编写的代码:

func configureTimerWithCounter(counter: Double) {

    let size = CGSizeMake(self.contentFrame.width, 6)
    UIGraphicsBeginImageContext(size)
    let context = UIGraphicsGetCurrentContext()
    UIGraphicsPushContext(context!)

    // Draw line
    let path = UIBezierPath()
    path.lineWidth = 100

    path.moveToPoint(CGPoint(x: 0, y: 0))

    let counterPosition = (self.contentFrame.width/30)*CGFloat(counter)
    path.addLineToPoint(CGPoint(x: counterPosition, y: 0))

    UIColor.greenColor().setStroke()
    UIColor.whiteColor().setFill()
    path.stroke()
    path.fill()

    // Convert to UIImage
    let cgimage = CGBitmapContextCreateImage(context);
    let uiimage = UIImage(CGImage: cgimage!)

    // End the graphics context
    UIGraphicsPopContext()
    UIGraphicsEndImageContext()

    self.timerImage.setImage(uiimage)

}