我试图通过调用watchOS2类的animateWithDuration来动画animateWithDuration应用程序中组的宽度。这样做的目的是向用户展示一条横线,它在一段时间内从右到左减小宽度(就像计时器一样):
self.timer.setWidth(100)
self.animateWithDuration(NSTimeInterval(duration)) {
self.timer.setWidth(0)
}然而,我看到的是,一旦动画开始,速度非常慢,然后它增加。当动画即将停止时(当计时器宽度接近于0),动画再次减慢。我希望在动画的持续时间内速度是相同的。
以前有人有过这个问题吗?任何帮助都是非常感谢的!谢谢
发布于 2016-08-03 17:36:19
我制作了一个简单的例子,说明我想在watchOS2应用程序中使用核心图形动画的计时器。您可以找到项目这里
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)
}发布于 2016-07-31 03:35:55
WatchOS 2没有提供一种指定定时函数的方法,因此动画仅限于使用EaseInEaseOut曲线(它开始缓慢,速度加快,最后减速)。
您可以尝试使用核心图形渲染行,或者使用一系列WKInterfaceImage框架来平滑地动画这一行。
https://stackoverflow.com/questions/38680373
复制相似问题