gpt4 book ai didi

ios - UIViewPropertyAnimator 未按预期工作

转载 作者:行者123 更新时间:2023-11-29 05:31:15 25 4
gpt4 key购买 nike

当用户点击 UIView 时,我尝试为 UIView 和 imageView 制作动画。这是我的代码:

// When the user taps on the featured story image view
@objc func feturedStoryTapped() {

/*featuredStoryView.layer.zPosition = 1

// Hide the necessary elements
self.featuredTitle.isHidden = true
self.bookTitle.isHidden = true
self.authorName.isHidden = true

// Unhide the necessary elements
self.exitButton.isHidden = false*/

let animator = UIViewPropertyAnimator(duration: 0.9, dampingRatio: 0.4, animations: {

self.featuredStoryView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
self.bookCover.frame = CGRect(x: 100, y: 75, width: 250, height: 280)

})

animator.startAnimation()

}

预期行为:当我点击 UIView 一次时, View 应该占据整个屏幕,而 imageView 应该缩小一点。

问题问题是,当我点击一次 View 时, View 占据整个屏幕,但 imageView 不会缩小,只有当我第二次点击时它才会缩小。

我希望当我点击 View 一次时执行这两个任务。我将添加一个 GIF 来帮助理解。

GIF

最佳答案

修复它,只需在属性动画器内的两行代码之间添加 view.layoutIfNeeded() 即可。

// When the user taps on the featured story image view
@objc func feturedStoryTapped() {

/*featuredStoryView.layer.zPosition = 1

// Hide the necessary elements
self.featuredTitle.isHidden = true
self.bookTitle.isHidden = true
self.authorName.isHidden = true

// Unhide the necessary elements
self.exitButton.isHidden = false*/

let animator = UIViewPropertyAnimator(duration: 0.9, dampingRatio: 0.4, animations: {

self.featuredStoryView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
Self.view.layoutIfNeeded()

self.bookCover.frame = CGRect(x: 100, y: 75, width: 250, height: 280)

})

animator.startAnimation()

}

关于ios - UIViewPropertyAnimator 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57533221/

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