gpt4 book ai didi

iOS 核心动画 : Show and hide effect

转载 作者:行者123 更新时间:2023-11-29 00:47:19 26 4
gpt4 key购买 nike

我想使用 Core Animation 创建一个动画,例如:

  • Image A is showed from 1s to 3s. After 3s, hide it.
  • Image B is showed from 5s to 7s. After 7s, hide it.

我的代码:

    var animation = CABasicAnimation(keyPath: "opacity")
animation.duration = 3.0
// animate from fully visible to invisible
animation.fromValue = NSNumber(float: 1.0)
animation.toValue = NSNumber(float: 0.0)
animation.beginTime = 2
animation.removedOnCompletion = true
layer1.addAnimation(animation, forKey: "animateOpacity")

animation = CABasicAnimation(keyPath: "opacity")
animation.duration = 3.0
// animate from fully visible to invisible
animation.fromValue = NSNumber(float: 1.0)
animation.toValue = NSNumber(float: 0.0)
animation.beginTime = 5
animation.removedOnCompletion = true
layer2.addAnimation(animation, forKey: "animateOpacity")

我该如何实现它?谢谢:)

最佳答案

它可以有多种方式

检查链接...<强> http://www.appcoda.com/view-animation-in-swift/

override func viewWillAppear(animated: Bool) {

let firstImageView = UIImageView(image: UIImage(named: "bg01.png"))
firstImageView.frame = view.frame
view.addSubview(firstImageView)

imageFadeIn(firstImageView)

}

func imageFadeIn(imageView: UIImageView) {

let secondImageView = UIImageView(image: UIImage(named: "bg02.png"))
secondImageView.frame = view.frame
secondImageView.alpha = 0.0

view.insertSubview(secondImageView, aboveSubview: imageView)

UIView.animateWithDuration(2.0, delay: 2.0, options: .CurveEaseOut, animations: {
secondImageView.alpha = 1.0
}, completion: {_ in
imageView.image = secondImageView.image
secondImageView.removeFromSuperview()
})

}

关于iOS 核心动画 : Show and hide effect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38477813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com