【问题标题】:move UIView within a form在表单内移动 UIView
【发布时间】:2014-08-11 18:08:44
【问题描述】:

所以在我的UIViewController 中,我还有 2 个视图。

如果用户在前一个UIViewController 上选择一个选项,则此视图会加载两个子视图。如果用户选择另一个选项,它只会加载第二个选项。

如果顶部视图被隐藏,我希望能够将第二个视图(底视图)移动到顶部。 但是当我尝试更改视图的Layer.Frame.Y 值时,它实际上并没有移动视图。但是我可以通过使用断点看到值发生变化。

这就是我所做的。

我已经在课堂上声明了这一点。

public float dateAndTimeViewYWithoutOtherTypes = 38f;
public float dateAndTimeViewYWithOtherTypes = 81f;

在我的 ViewDidLoad 中,

if (this.label.Text == "Other") {
    this.view1.Hidden = false;
    this.view2.Layer.Frame = new RectangleF (this.view2.Layer.Frame.X, dateAndTimeViewYWithOtherTypes, this.view2.Layer.Frame.Width, this.view2.Layer.Frame.Height);
} else {
    this.view1.Hidden = true;
    this.view2.Layer.Frame = new RectangleF (this.view2.Layer.Frame.X, dateAndTimeViewYWithoutOtherTypes, this.view2.Layer.Frame.Width, this.view2.Layer.Frame.Height);
}

谁能解释一下我错过了什么或做错了什么?

谢谢。

【问题讨论】:

    标签: ios uiview xamarin.ios xamarin


    【解决方案1】:

    将您的代码移动到 viewWillAppear - 框架几何图形尚未在 viewDidLoad 中设置。

    【讨论】:

    • 感谢史蒂夫的快速回复。但是我将代码移到 viewWillAppear 并没有什么区别。 Y 位置没有改变。
    • 抱歉@user3866010,将操作框架的代码从 viewDidLoad 移动到 viewWillAppear 通常可以解决 Objective-C 中的问题。我认为使用 monotouch/xamarin 也是如此。
    • 非常感谢您提供的信息。我相信它在某些时候会很有用。我会继续尝试这个。令人困惑的部分是一切都被调用,值是变化,第一个视图被隐藏但没有位置变化。但我确定我在某处遗漏了一些东西。
    【解决方案2】:

    我想通了。

    this.txtView.Transform = CGAffineTransform.MakeTranslation (0, -88).

    出于某种原因,我必须将XY 的数字加倍,但它可以工作。所以只需要将它上移 44px 但我必须做 88px 但它似乎工作得很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多