【问题标题】:Animation dont execute动画不执行
【发布时间】:2015-04-07 11:06:14
【问题描述】:

我想在按钮操作上更改 mapView 的大小,所以我有两个函数可以做到这一点。

func makeFullScreenMap() {
    println(self.heightConstraint.constant)
    self.heightConstraint.constant = self.tableView.frame.height
    println(self.heightConstraint.constant)
    self.mapView.setNeedsUpdateConstraints()
    UIView.animateWithDuration(5, animations: { () -> Void in
        self.mapView.layoutIfNeeded()
    })

}

func makeHideScreenMap() {

    self.heightConstraint.constant = 0
    self.mapView.setNeedsUpdateConstraints()
    UIView.animateWithDuration(5, animations: { () -> Void in
        self.mapView.layoutIfNeeded()
    })
}

否则,我在跟踪按钮状态并选择我需要使用的确切方法时采取了行动。

  @IBAction func fullScreen(sender: AnyObject) {

        println(changeMapButton.state.rawValue)

        if changeMapButton.state == UIControlState.Highlighted {
            makeFullScreenMap()
            changeMapButton.selected = true

        } else {
            changeMapButton.highlighted = true
            makeHideScreenMap()
        }

    }

问题是 - 当它向下动画时,它会用动画制作它并慢慢使 mapView 变大。当我使用方法 makeHideScreenMap() 时,它会立即发生变化,然后滚动地图视图动画。我需要它像换帧一样缓慢地制作动画。有什么建议吗?

【问题讨论】:

  • 你可以尝试在动画块中用 self.view.layoutIfNeeded() 替换 self.mapView 吗?
  • @Greg 如果您要发布答案 - 我会对其进行评分,因为它解决了我的问题!非常感谢!

标签: ios swift animation uiview mkmapview


【解决方案1】:

您应该在动画块内将self.mapView.layoutIfNeeded() 替换为self.view.layoutIfNeeded(),因为您布局的约束是视图的子视图而不是mapView。

【讨论】:

    【解决方案2】:

    尝试使用它制作动画。请根据您的需要管理坐标。

    let trans = CGAffineTransformScale(mapView.transform, 1.00, 1.00)
    UIView .animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
    
            self. mapView.transform = CGAffineTransformScale(self. mapView.transform, 100.0, 100.0)
    
            }, completion: {
                (value: Bool) in
        })
    

    【讨论】:

    • 我需要更改一些限制条件,所以你的代码无法满足我的需要
    • 无论如何,它不适用于自动布局。您需要调整约束并更新。
    猜你喜欢
    • 2014-02-24
    • 1970-01-01
    • 2011-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-12
    相关资源
    最近更新 更多