Help us understand the problem. What is going on with this article?

UIViewKeyframeAnimationの動き [curveEaseInOutになっている?]

More than 1 year has passed since last update.

swiftでアニメーションのあるアプリを作っていた時に

UIViewkeyframeAnimation
を利用していた。

次のように記述して、1秒ごとにラベルがスタートして行くように設定した。

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var one: UILabel!
    @IBOutlet weak var two: UILabel!
    @IBOutlet weak var three: UILabel!
    @IBOutlet weak var four: UILabel!
    @IBOutlet weak var five: UILabel!

    @IBAction func start(_ sender: Any) {


        UIView.animateKeyframes(withDuration:5.0, delay:0.0,  animations:
            {




                UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.2, animations: {
                    self.one.center = CGPoint(x:70, y:0)

                })

                UIView.addKeyframe(withRelativeStartTime: 0.2, relativeDuration: 0.2, animations: {
                    self.two.center = CGPoint(x:223, y:0)

                })

                UIView.addKeyframe(withRelativeStartTime: 0.4, relativeDuration: 0.2, animations: {
                    self.three.center = CGPoint(x:384, y:0)

                })

                UIView.addKeyframe(withRelativeStartTime: 0.6, relativeDuration: 0.2, animations: {
                    self.four.center = CGPoint(x:531, y:0)

                })

                UIView.addKeyframe(withRelativeStartTime: 0.8, relativeDuration: 0.2, animations: {
                    self.five.center = CGPoint(x:680, y:0)

                })


        }
        )       

    }


}


実際に動かすと上のように1秒ごとに動かずに徐々に速く動くようになり最後に向かって、ゆっくりになっていた。 ちゃんと1秒ごとに同じ速さ・同じタイミングで動かしたいと思った。

open class func animateKeyframes(

withDuration duration: TimeInterval,
delay: TimeInterval,
options: UIViewKeyframeAnimationOptions = [],
animations: @escaping () -> Swift.Void,
completion: ((Bool) -> Swift.Void)? = nil)

animateKeyframesにはoptionがある。
そのoptionに指定できるのが

public struct UIViewKeyframeAnimationOptions : OptionSet {

public init(rawValue: UInt)


public static var layoutSubviews: UIViewKeyframeAnimationOptions { get }

public static var allowUserInteraction: UIViewKeyframeAnimationOptions { get } // turn on user interaction while animating

public static var beginFromCurrentState: UIViewKeyframeAnimationOptions { get } // start all views from current value, not initial value

public static var `repeat`: UIViewKeyframeAnimationOptions { get } // repeat animation indefinitely

public static var autoreverse: UIViewKeyframeAnimationOptions { get } // if repeat, run animation back and forth

public static var overrideInheritedDuration: UIViewKeyframeAnimationOptions { get } // ignore nested duration

public static var overrideInheritedOptions: UIViewKeyframeAnimationOptions { get } // do not inherit any options or animation type


public static var calculationModeLinear: UIViewKeyframeAnimationOptions { get } // default

public static var calculationModeDiscrete: UIViewKeyframeAnimationOptions { get }

public static var calculationModePaced: UIViewKeyframeAnimationOptions { get }

public static var calculationModeCubic: UIViewKeyframeAnimationOptions { get }

public static var calculationModeCubicPaced: UIViewKeyframeAnimationOptions { get }

}

それぞれ試してみた。


UIView.animateKeyframes(withDuration:5.0, delay:0.0, options:[.layoutSubviews], animations:

こんな感じで試ししてみたが、同じ間隔でスタートし、同じ速さで動くものはなかった?

無理なのか?

hyoutann
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした