ios - Swift:在动画过程中中途更改 UIImageView 图像
问题描述
我有这个代码来创建动画imageView
:
imageView.layer.anchorPoint = CGPoint(x: 0, y: 0.5)
var transform = CATransform3DIdentity
transform.m34 = -0.001
imageView.layer.transform = transform
UIView.animate(withDuration: 3) {
self.imageView.layer.transform = CATransform3DRotate(transform, .pi, 0, 1, 0)
self.imageViewCenterConstraintX.constant = 0
self.view.layoutIfNeeded()
}
在此代码imageView
中旋转 180 度。我想在imageView
旋转 90 度后更改图像。
解决方案
You should chain the two animations, each rotating with pi/2.
imageView.layer.anchorPoint = CGPoint(x: 0, y: 0.5)
var transform = CATransform3DIdentity
transform.m34 = -0.001
imageView.layer.transform = transform
UIView.animate(withDuration: 1.0, animations:
{
self.imageView.layer.transform = CATransform3DRotate(transform, .pi/2, 0, 1, 0)
self.imageViewCenterConstraintX.constant = 0
})
{
(bCompleted) in
if (bCompleted)
{
self.imageView?.layer.transform = CATransform3DRotate(transform, .pi/2, 0, 1, 0)
}
UIView.animate(withDuration: 1.0, animations:
{
self.imageView.layer.transform = CATransform3DRotate(transform, .pi*0.999, 0, 1, 0)
self.imageView.image = UIImage.init(named:"anotherImage")
},
completion:
{
(bFinished) in
//Whatever
})
}
推荐阅读
- angular - 在子组件中等待 API 时的角度“加载”
- regex - 如何在 VB.net 的 DataSet.Tables.Select() 中使用正则表达式
- sql - 仅在 VoltDB 中更新必要的字段
- python - Plotly fig.show() 给出 TypeError: 'NoneType' object is not callable
- reactjs - 如果文本很长,则在悬停时 React 'react-data-table-component' 不显示工具提示
- asp.net-core-mvc - 无法使用数据播种数据库
- excel - 如何在excel中按升序对一行中不同长度的单词进行排序?
- react-native - 来自 URL 的 PNG 图像未在本机 android 4.4.2 中显示
- c# - “不能重复使用 obectpool 中的子弹。”
- reactjs - 下载公共文件夹中的示例文件(反应)