【问题标题】:Issues with animating view for new screen sizes新屏幕尺寸的动画视图问题
【发布时间】:2014-10-05 15:35:19
【问题描述】:

在我的应用程序中,我的主视图控制器中有两个视图。一种是输入有关预算的详细信息。另一个用于查看预算的当前状态。

当在条目视图上点击输入按钮时,该视图会向下滑动以显示当前预算视图。

在 viewWillAppear 中,如果点击了 enter 按钮但视图没有移动(当应用完全关闭并重新打开时会发生这种情况),我会执行一些代码。

重置按钮的作用与输入按钮相反,并将视图向上滑动。

问题在于,有时当点击重置按钮时,视图开始向上滑动,但随后在视图底部附近停止。在我更新我的应用程序以在 iPhone 6 和 iPhone 6 Plus 上工作之前,这一切都很好,所以我认为我的坐标计算有问题。我只是无法弄清楚。这是卡住时的样子:

重置按钮:

    self.budgetEntryView.hidden = false
    resetButtonNav.enabled = false

    UIView.animateWithDuration(0.3, delay: 0, options: .CurveLinear, animations: {
        self.budgetEntryView.center = CGPointMake(self.budgetEntryView.center.x, self.budgetEntryView.center.y - 500)
        }, completion: { (finished:Bool) in
            self.budgetDisplayView.hidden = true

viewWillAppear:

        if enterButtonTapped == true && self.budgetEntryView.center.y != 784 {

        UIView.animateWithDuration(0.3, delay: 0, options: .CurveLinear, animations: {
            self.budgetEntryView.center = CGPointMake(self.budgetEntryView.center.x, self.budgetEntryView.center.y + 500)
            }, completion: { (finished:Bool) in self.budgetEntryView.hidden = true })
        }

输入按钮:

        UIView.animateWithDuration(0.3, delay: 0, options: .CurveLinear, animations: {
        self.budgetEntryView.center = CGPointMake(self.budgetEntryView.center.x, self.budgetEntryView.center.y + 500)
        }, completion: { (finished:Bool) in self.budgetEntryView.hidden = true })

【问题讨论】:

  • 你使用自动布局吗?如果是这样,您可能会考虑为约束设置动画,而不是视图的宽度/高度/位置。
  • 不。我很早就尝试使用自动布局,但我真的不喜欢它。我将它用于 Today Widget,因为它是一个更简单的 UI,但我想避免将它用于主应用程序。代码是否没有明显错误,可能会导致您看到的问题?
  • 对不起,我看不到明显的东西。在代码中放置几个​​ println() 语句来检查中心坐标是否发生了问题。最好使用CGPoint(...) 而不是CGPointMake(...)
  • 啊,通过使用 println,我发现在某些时候它会跳转到 868,因为它应该是 1368。感谢您的帮助。我会继续测试,看看能不能找到问题。

标签: ios uiview swift animatewithduration


【解决方案1】:

一旦我按照建议使用 println 来查找问题,修复就相当简单了。

基本上,我只需要添加视图将在新屏幕尺寸上定位的坐标,如下所示:

    if enterButtonTapped == true && self.budgetEntryView.center.y != 784 && self.budgetEntryView.center.y != 868 && self.budgetEntryView.center.y != 740 && self.budgetEntryView.center.y != 833.5 {

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    相关资源
    最近更新 更多