2016-07-31 3 views
0

クラスのanimateWithDurationを呼び出して、watchOS2アプリケーションでグループの幅をアニメートしようとしています。私は、すぐにアニメーションが始まると見ていることがwatchOS2 animateWithDurationが遅くなり、スピードアップします

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

:アイデアは、ユーザーの時間(タイマーのようなもの)の期間にわたって右から左にその幅を減少させる水平線を表示することです速度は非常に遅く、次にそれは増加する。アニメーションが停止しようとしているとき(タイマーの幅が0に近いとき)、アニメーションは再び減速します。 私はアニメーションの長さに亘って同じスピードにします。

誰もこの問題を以前に持っていましたか?どんな助けもありがとう!ありがとう

答えて

-1

watchOS2アプリでCore Graphicsを使用してアニメーション化したいタイマーの簡単な例を作成しました。ここで私が作ったコードだ :

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) 

} 
あなたはプロジェクト here

UPDATEを見つけることができます

1

WatchOS 2はタイミング関数を指定する方法を提供していないため、アニメーションはEaseInEaseOutカーブを使用することに制限されています(遅くなり、スピードアップし、最後に遅くなります)。

using Core Graphics to render the lineを試すか、一連のWKInterfaceImageフレームを使用して、スムーズにアニメーション化することができます。

関連する問題