【问题标题】:animateWithDuration jumps (sometimes) to final position without animationanimateWithDuration 跳转(有时)到没有动画的最终位置
【发布时间】:2015-12-16 19:30:23
【问题描述】:

(1) 当我单击注释/固定时,我的动画效果很好。一个表格视图向上滑动。当我单击地图 (didDeselectAnnotationView) 时,tableview 会跳转到最终位置。 但是:当我单击一个单元格 (didSelectRowAtIndexPath) 时,动画会完美地向下滑动。

那么点击地图和点击tableViewCell有什么区别呢?它们都使用相同的功能。

(2) 还有一点: 在我的 tableView 中,我正在我的单元格中加载内容。当我尝试设置图像时,图像正确显示,但会终止所有动画。之后,每个向上/向下动画都在跳跃。

我很困惑。没有错误。我读到:当 animateWithDuration 有冲突或同时有 UI 动作时, animateWithDuration 会跳转。好的。但我该如何处理呢?有人有教程或一些一般提示吗?我不知道在哪里寻找我的错误。

我用 dispatch_asycn 尝试了一点,但没有任何效果。

感谢您的帮助,当英语不完美时,我们深表歉意:)

一些代码: (1) 动画:

 func animateAllInformationAboutSingleDevice(up: Bool) {
    //  dispatch_async(dispatch_get_main_queue(), {
    if up {
        self.animationNSLayoutConstraint.constant += CGFloat(255)
    } else {
        self.animationNSLayoutConstraint.constant -= CGFloat(255)
    }

    UIView.animateWithDuration(Constants.animationTime, animations: { () -> Void in
        self.tableViewController.layoutIfNeeded()
        }, completion: {
            (value: Bool) in
            self.tableViewController.reloadData()
    })

    //  })
}

删除功能:

 func deleteAllInformationAboutVehicle(annotation: MKAnnotation) {

    if let carAnnotation = annotation as? CarAnnotation {

        if carAnnotation.itemId != "" {
            setImageToDefaultImage()
            //dispatch_async(dispatch_get_main_queue(), {
            self.animateInformationScreen(false)
            //})

        }
    }
}

(2) 在 tableView 中设置图像:

dispatch_async(dispatch_get_main_queue(), {
            cell.carImage?.clipsToBounds = true

            if let image = globalCurrentImageOfCar {

                cell.carImage.image = GUITools.cropToBounds(image)

            }
        })

【问题讨论】:

    标签: ios swift animation dispatch-async


    【解决方案1】:

    对于您的第一个问题,请在更改约束常量并运行动画块之前尝试调用self.tableViewController.layoutIfNeeded()

    可能是在尝试将动画设置为新位置之前,视图尚未布置到其先前位置。

    【讨论】:

    • 我在 viewDidAppear() 中调用了 self.tableViewController.layoutIfNeeded() 在 vi​​ewDidLoad() 中的替代方法,但两者都不起作用。
    【解决方案2】:

    好吧奇怪的事情......

    在我的func mapView(mapView: MKMapView, didDeselectAnnotationView view: MKAnnotationView) { 中调用tableViewController.reloadDate() 非常重要

    很遗憾,我不知道为什么。 我认为,每个函数/代码或其他任何东西都必须在动画开始之前调用 reloadData 。如果有人知道,请发表评论。 @Christopher Kevin Howell:感谢您的帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 2014-02-13
      • 2019-10-02
      • 1970-01-01
      • 2015-08-14
      相关资源
      最近更新 更多