gpt4 book ai didi

ios - Swift:UIView.transitionWithView 完成 block 问题

转载 作者:搜寻专家 更新时间:2023-11-01 05:40:53 24 4
gpt4 key购买 nike

我正在尝试使用以下代码让我的 UIImageView (self.posterImageview) 在一组带有动画的 UIImage 中循环:

 func animatePoster (imageArray: [UIImage], count: Int = 0)
{
UIView.transitionWithView
(
self.posterImageview,
duration: 2,
options: UIViewAnimationOptions.TransitionFlipFromBottom,
animations:
{
self.posterImageview.image = imageArray[count]
},
completion:
{
finished in
if (count == imageArray.count - 1) // Last image
{
self.animatePoster(imageArray)
}
else
{
self.animatePoster(imageArray, count: count + 1)
}
}
)

}

然而,完成 block 似乎并没有像我想象的那样工作。现在,它在所有图像中反复闪烁,不允许在移动到下一个之前播放完整的动画。增加动画的持续时间没有帮助,当我对递归设置限制时(例如,当我到达最终图像时结束),然后所有图像都会快速循环,除了最后一个,它正确地动画。

任何见解都值得赞赏。

最佳答案

我对 show animation 做了一些不同的改动。请检查它是否对您有帮助。

现在我已经添加了虚拟代码

override func viewDidLoad() {
super.viewDidLoad()

self.arrimages = NSArray (arrayLiteral: UIImage(named: "1.png")!,UIImage(named: "2.png")!,UIImage(named: "3.png")!,UIImage(named: "4.png")!)

print("Images array = \(self.arrimages)")

self.posterImageview.image = UIImage(named: "1.png")!
self.animatePoster(self.arrimages as! [UIImage], count: 1)

}


func animatePoster (imageArray: [UIImage], count: Int = 0){

print("count value = \(count)")

UIView.transitionWithView(self.posterImageview, duration: 5, options: UIViewAnimationOptions.TransitionFlipFromBottom, animations: {

}, completion: { (finished: Bool) -> () in

let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC)))

dispatch_after(delayTime, dispatch_get_main_queue()) {
self.posterImageview.image = imageArray[count]
}


if (count == (imageArray.count - 1)) // Last image
{
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(4 * Double(NSEC_PER_SEC)))

dispatch_after(delayTime, dispatch_get_main_queue()) {
self.animatePoster(imageArray)
}
}
else
{
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(4 * Double(NSEC_PER_SEC)))

dispatch_after(delayTime, dispatch_get_main_queue()) {
self.animatePoster(imageArray, count: count + 1)
}
}
})

}

关于ios - Swift:UIView.transitionWithView 完成 block 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30654694/

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