ios - 在 UIView.animateWithDuration 之前完全取消隐藏 View

标签 ios uiview uiviewanimation

我正在使用 UIView.animateWithDuration 在点击识别时在 View 中滑动。这工作正常,除了第一次, View 未隐藏稍微晚一点,它突然出现在动画的中途。后续的显示/隐藏操作没有这个问题。

我是这样实现的

    textBlurBackground.hidden = false
    descriptionOutlet.hidden = false
    UIView.animateWithDuration(0.4, delay: 0.0, options: nil, animations: {
        self.textBlurBackground.transform = CGAffineTransformMakeTranslation(0, 0)
        self.descriptionOutlet.transform = CGAffineTransformMakeTranslation(0, 0)
        }, completion: nil)

所以看起来,即使我首先设置“隐藏”属性(在前两行),这也会以某种方式延迟并且仅在动画已经运行时执行。请注意,这只会在第一次创建 View 时发生;随后的显示/隐藏操作工作正常( View 在动画之前完全不隐藏)。

我注意到有一个“完成” Hook - 是否有等同于准备阶段的东西? IE。在 View 完全取消隐藏之前不要启动动画。

最佳答案

多亏了评论中的时间建议(并且运行缓慢),我可以弄清楚,在这种情况下,这不是时间问题,而是 View 的尺寸在第一个 View 时不知何故不正确加载。例如。我在 viewDidLoad 中有

override func viewDidLoad() {
    textBlurBackground.hidden = true
    descriptionOutlet.hidden = true
    descriptionOutlet.transform = CGAffineTransformMakeTranslation(-textBlurBackground.bounds.width, 0)
    textBlurBackground.transform = CGAffineTransformMakeTranslation(-textBlurBackground.bounds.width, 0)
}

此时 textBlurBackground.bounds.width 不正确;该代码不会通过 textBlueBackground View 的负宽度将这些 View 完全移出屏幕。但是,一旦加载 View ,后续的显示/隐藏操作就会正常工作,因为它可以获得正确的 View 大小。

因此,这似乎是自动布局大小调整的问题,其中“textBlurBackground.bounds.width”在初始 View 加载时不正确。这很奇怪,因为它不会改变大小,所以我可能需要指定更多约束。

关于ios - 在 UIView.animateWithDuration 之前完全取消隐藏 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30148046/

相关文章:

ios - 一个棘手的 Objective-C block 行为

ios - (ios10.2)(swift3) 如何判断用户是否点击了本地通知?

ios - 在容器 View Controller 中添加/删除时如何为 subview Controller 设置动画?

ios - 如何在我的 iOS swift listview Controller 中显示 firebase 信息?

ios - 如何在 UITableView 中的单元格之间添加分隔符单元格/uiview?

ios - 以编程方式在 Xcode Playgrounds 中创建 UIView 子类

ios - 如何使用自定义转换 ios7 制作 uiview 全屏 View Controller

ios - 使用 nib 中的 View 重新加载 UIView 属性

ios - UIView animatewithDuration - 移除动画

iphone - 获取动画 ScrollView 的当前位置