ios - 在 UIView.animate 期间忽略 withDuration
问题描述
当点击按钮时,我正在尝试为 AVPlayerLayer 的不透明度设置动画。这是我的功能:
@IBAction func boutonTapped(_ sender: UIButton) {
if(paused){
UIView.animate(withDuration: 5.0, animations: {
self.avPlayerLayer.opacity = 1.0
}, completion: nil)
//avPlayer.play()
}else{
UIView.animate(withDuration: 5.0, animations: {
self.avPlayerLayer.opacity = 0
}, completion:nil)
//avPlayer.pause()
}
paused = !paused
}
启动了不透明动画,但速度非常快(大约 0.5 秒)。我尝试将持续时间更改为 10s 并且动画是相同的
我试图self.view.layoutIfNeeded()
在动画块内添加没有效果。
你有什么想法吗?谢谢 !
解决方案
不要为 of 设置动画,而是opacity
尝试avPlayerLayer
为要添加alpha
的位置设置动画,即customView
avPlayerLayer
@IBAction func boutonTapped(_ sender: UIButton) {
UIView.animate(withDuration: 5.0) {
self.customView.alpha = paused ? 1.0 : 0.0 //here...
paused ? self.avPlayer.play() : self.avPlayer.pause()
}
paused = !paused
}
没有必要打电话self.view.layoutIfNeeded()
。
推荐阅读
- unity3d - ARcore Camera 纹理只能从 Unity Editor 获得
- dataframe - 重命名多索引元组熊猫数据框
- javascript - 使用什么代替 ActiveXObject 使其跨浏览器兼容
- sql - 按销售人员计算销售额
- python - pycharm工具栏中未列出变量
- coldfusion - 本地主机 Coldfusion 安装在页面上显示 cfquery 参数(不与 ODBC 对话)
- python - 将 EGCD 方程转换为 Python
- material-design - 如何在展开时设置 Angular 材质的 mat-expansion-panel-header 的高度?
- c# - TwoWay Stream 中是否有构建
- php - 无法使用 Apache 路由到 CakePHP 控制器