MonoTouch:如何在运行时更改控件的位置? [英] MonoTouch: How to change control's location at runtime?

查看:33
本文介绍了MonoTouch:如何在运行时更改控件的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时更改 UIImageView 的位置.在 IB 中,我可以更改 X 坐标以重新定位它.所以,我试过这个代码:

I want to change the location of an UIImageView at runtime. In IB, I can change X coordinate to relocate it. So, I tried this code:

imageView.Frame.X = 25;

但它没有任何影响.为什么?我对其他控件也有同样的问题.如何让它发挥作用?

But it doesn't have any effect. Why? I have the same problem for other controls as well. How to make it work?

推荐答案

Frame 属性是一个值类型,这意味着如果你这样做:

The Frame property is a value type, this means that if you do:

imageView.Frame.X = 25

你实际上在做什么:

var temp = imageView.Frame;
temp.X = 25;

该值永远不会到达 imageView.对于值类型,您必须分配一个完全构造的类型,例如:

The value never reaches the imageView. With value types, you have to assign a fully constructed type, so for example:

var current = imageView.Frame;当前.X = 25;imageView.Frame = 当前;

var current = imageView.Frame; current.X = 25; imageView.Frame = current;

这篇关于MonoTouch:如何在运行时更改控件的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆