animateWithDuration跳转(有时)到没有动画的最终位置

时间:2015-12-15 15:08:19

标签: ios swift animation dispatch-async

(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)

            }
        })

2 个答案:

答案 0 :(得分:0)

对于第一个问题,请在更改约束常量并运行动画块之前尝试调用AlarmManager

可能会出现这样的情况,即在尝试为其新视图设置动画之前,该视图尚未布置到之前的位置。

答案 1 :(得分:0)

好的奇怪的是......

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

非常重要

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