【问题标题】:AnimateWithDuration block is not correctAnimateWithDuration 块不正确
【发布时间】:2015-01-18 21:00:52
【问题描述】:

我正在尝试使用 AnimateWithDuration 块为 UIView 设置动画。这个 UIView 包含两个 UIScrollView 和两个按钮。一个按钮是向下过滤,另一个是过滤。喜欢图片:

所以向下滚动我使用这个块:

@IBAction func FilterEntry(sender: AnyObject) {

    self.FilterDown.hidden = true
    self.FilterDownIcon.hidden = true

    var duration = 0.5
    UIView.animateWithDuration(duration, animations: {
        self.ColouredSquare.frame = CGRect(x: 0, y: 65, width: 400, height: 212)

        }, completion: { finished in
            self.FilterUPIcon.hidden = true
            self.FilterUP.hidden = true
            self.DateScroll.hidden = false
            self.EventScroll.hidden = false
            self.FilterUPIcon.hidden = false
            self.FilterUP.hidden = false
     })
}

效果很好,而且滚动效果很好。但是当我走另一条路时,UIView 上升了,然后 UIView 上升了,但 UIScollviews 的删除持续到动画结束然后消失。我可以从代码中看出这是有道理的,但是当它下降时运行平稳,但上升时看起来很糟糕。

这是我启动 UIView 的代码:

 @IBAction func FilterUPEvent(sender: AnyObject) {

        self.FilterUP.hidden = true
        self.FilterUPIcon.hidden = true

        var duration = 0.5
        UIView.animateWithDuration(duration, animations: {
            self.ColouredSquare.frame = CGRect(x: 0, y: 65, width: 400, height: 20)

            }, completion: { finished in

                self.EventScroll.hidden = true
                self.DateScroll.hidden = true
                self.FilterUP.hidden = true
                self.FilterUPIcon.hidden = true
                self.FilterDown.hidden = false
                self.FilterDownIcon.hidden = false
        })
 }

【问题讨论】:

  • 有什么问题?另外,如果你想scroll,你为什么要改变一些东西的frame
  • 嗨,它向下滚动很可爱,但向上滚动背景很好,但然后突然删除 UIScrollViews。这是有道理的,因为在闭包块中我已将它们设置为隐藏。不过往下走好像还挺顺​​利的。
  • 您可以在动画块中使用UIViewalpha 属性来淡入和淡出视图。

标签: ios swift uiview uiscrollview


【解决方案1】:

尝试在动画块上方设置self.colouredSquare.clipToBounds = true

clipToBounds 是一个布尔值,用于确定子视图是否 限制在视图的范围内。将此值设置为 true 原因 要裁剪到接收器边界的子视图。如果设置为假, 其帧超出接收器可见边界的子视图 不被剪裁。默认值为 false。

【讨论】:

    猜你喜欢
    • 2011-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多