iOS 动画故障,Y 坐标问题

标签 ios iphone swift uiview uiviewanimation

几个小时以来,我一直在努力解决最小的动画故障。我的代码成功地将 View 移出屏幕,然后将其动画返回。它获得了正确的 x 坐标,但 Y 轴有我不明白的行为。代码如下:

func listTrans_slideIn (slideFrom: String) {
    //var newFrame = tableView.frame
    tableView.frame.origin.x = 1000
    //tableView.frame.origin.y = 100
    print("Table pushed to side")

    UIView.animateKeyframesWithDuration(1.375 /*Total*/, delay: 0.0, options: UIViewKeyframeAnimationOptions.CalculationModeLinear, animations: {
        UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration: 1/1, animations:{
            self.tableView_toTLG_Top.constant = 130
            self.tableView_toSV_Left.constant = 0
            self.tableView_toSV_Right.constant = 0
            self.setupView()

            //newFrame.origin.y = self.hdrBox.frame.height+50
            //newFrame.origin.x = 0
            //self.tableView.frame = newFrame

            self.tableView.layoutIfNeeded()
        })
        },
        completion: { finished in
            if (!finished) { return }

        })
}

奇怪的行为是,如果我将正确的 y 坐标放入动画关键帧中,它的位置会太高,但随后会稳定在正确的坐标处。如果我输入的 y 坐标太低,它会出现在正确的高度,但随后会变得太低。

如您所见,我尝试使用框架和约束。我尝试过更改将其移出屏幕的高度,但这似乎没有效果。

有人知道为什么我花了半天时间才看到这个错误吗?

最佳答案

你能尝试这样的事情吗:

  // Use the same value here and below, it moves it out of the screen
        self.tableView.center.y -= 500

 UIView.animateWithDuration(1.0, animations: { () -> Void in

       // Then it comes back 
           self.tableView.center.y += 500
    })

关于iOS 动画故障,Y 坐标问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36913680/

相关文章:

ios - 根据 UICollectionView 中 url 的 json 响应从应用程序内添加图像

iphone - 如何获取 subview 中导航栏的高度?

ios - 是否有任何 Swift SIMD 浮点类型都符合的协议(protocol)?

xcode - 一旦我最终使用它,我是否必须删除一个 sprite 节点?

iphone - 修复了 iPhone Safari 上的背景

ios - 制作 UIProgressView 圆角

ios - 如何创建一个包含大量文本和按钮的屏幕而不使用 UIWebView

ios - 在主视图顶部添加新 View (例如错误消息)时如何自动布局约束

ios - 在 Adob​​e 中打开时 PDF 的颜色与在预览中不同

ios - 如何检查是否启用了视差