ios - UIView 过渡动画不执行

标签 ios swift uiviewanimation uiviewanimationtransition

当 UIView 出现在屏幕上时,我正在尝试使用动画过渡。 UIView 正确显示,但出现时没有出现动画。

  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    let coreView = UIView(frame: CGRect(x: 10, y: 10, width: 100, height: 100))
    coreView.backgroundColor = UIColor.cyan
    coreView.layer.borderColor = UIColor.darkGray.cgColor
    coreView.layer.borderWidth = 8
    coreView.layer.cornerRadius = 15
    coreView.isHidden = true
    self.view.addSubview(coreView)

    //The transition occurs here
    UIView.transition(with: coreView, duration: 2, options: [.curveEaseInOut, .transitionCurlDown], animations: {

      coreView.isHidden = false
    }, completion: {_ in})

    }

最佳答案

不要操纵 coreView 的 isHidden 属性,而是使用 alpha 属性。

尝试将 coreView.isHidden = true 替换为 coreView.alpha = 0 并在动画 block 中将 coreView.isHidden = false 替换为 < strong>coreView.alpha = 1

我猜应该是这样。它应该动画。谢谢。

关于ios - UIView 过渡动画不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44398243/

相关文章:

ios - 如何在iOS中将PDF文件附加到邮件和发送邮件

ios - 在 OS X Mavericks 上安装 Calabash-cucumber 错误

swift - 时间戳事件匹配错误: Failed to find matching element

ios - UIView动画: simulating velocity

ios - 播放一次 UIImageView 动画并在播放后立即将其从内存中删除的最佳方法是什么?

ios - 动画图像到 UIImageView

iphone - 从 UIViewController 访问 UIView

ios - 在现有的 iOS 项目中使用 cocoapods

swift - 当 UIView 完全加载时如何收到通知

iOS 8 无法连接到 BLE。可以连接到 iOS 9