watchOS2 animateWithDuration启动速度慢并加速
问题描述:
我试图通过调用WKInterfaceController
类的animateWithDuration
来激活我的watchOS2应用程序中组的宽度。我们的想法是向用户展示其右降低其宽度的水平线遗留下来的一段时间(像一个定时器):watchOS2 animateWithDuration启动速度慢并加速
self.timer.setWidth(100)
self.animateWithDuration(NSTimeInterval(duration)) {
self.timer.setWidth(0)
}
但是我看到,一旦动画开始速度非常慢,然后增加。当动画即将停止时(当定时器宽度接近0时)动画再次减速。 我希望速度在动画的持续时间内保持不变。
有没有人有过这个问题?任何帮助表示赞赏!谢谢
答
我做了一个计时器的简单例子,我想用watchOS2应用程序中的Core Graphics进行动画制作。 你可以找到项目here
UPDATE: 下面是我做的代码:
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)
}
答
WatchOS 2没有提供指定定时功能的方法,所以动画仅限于使用EaseInEaseOut曲线(从最初开始缓慢,加速,然后减慢)。
您可以尝试using Core Graphics to render the line,或者使用一系列WKInterfaceImage帧来平滑地对线条进行动画处理。