2016-07-31 118 views
0

我試圖通過調用WKInterfaceController類的animateWithDuration來激活我的watchOS2應用程序中組的寬度。我們的想法是向用戶展示其右降低其寬度的水平線遺留下來的一段時間(像一個定時器):watchOS2 animateWithDuration啓動速度慢並加速

self.timer.setWidth(100) 
self.animateWithDuration(NSTimeInterval(duration)) { 
    self.timer.setWidth(0) 
} 

但是我看到,一旦動畫開始速度非常慢,然後增加。當動畫即將停止時(當定時器寬度接近0時)動畫再次減速。 我希望速度在動畫的持續時間內保持不變。

有沒有人有過這個問題?任何幫助表示讚賞!謝謝

回答

-1

我做了一個計時器的簡單例子,我想用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) 

} 
1

WatchOS 2沒有提供指定定時功能的方法,所以動畫僅限於使用EaseInEaseOut曲線(從最初開始緩慢,加速,然後減慢)。

您可以嘗試using Core Graphics to render the line,或者使用一系列WKInterfaceImage幀來平滑地對線條進行動畫處理。