在表单中移动UIView

时间:2014-08-11 18:08:44

标签: ios uiview xamarin.ios xamarin

所以在我的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);
}

任何人都可以向我解释一下我错过了什么或做错了吗?

谢谢。

2 个答案:

答案 0 :(得分:0)

将代码移至viewWillAppear - 尚未在viewDidLoad中设置框架几何体。

答案 1 :(得分:0)

我明白了。

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

出于某种原因,我必须加倍XY号,但它有效。所以只需要将其移动44px但我必须做88px但它似乎完美无缺。

相关问题