MonoTouch: How to change control's location at

2019-09-08 07:11发布

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?

3条回答
The star\"
2楼-- · 2019-09-08 07:20

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

imageView.Frame.X = 25

what you are actually doing is:

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

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

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

查看更多
看我几分像从前
3楼-- · 2019-09-08 07:27

// The Code is quite simple and self explanatory

dispatch_async(dispatch_get_main_queue(), ^{

    self.myimageView.frame = CGRectMake(140, 70, 140, 128);


});

By using >dispatch_async(dispatch_get_main_queue(), ^{ I made the code to run in the main queue, not in the background.

查看更多
\"骚年 ilove
4楼-- · 2019-09-08 07:33

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

imageView.Frame.X = 25

what you are actually doing is:

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

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

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

查看更多
登录 后发表回答