0

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?

newman
  • 6,841
  • 21
  • 79
  • 126

3 Answers3

3

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;

miguel.de.icaza
  • 32,654
  • 6
  • 58
  • 76
0

// 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.

Jasmeet
  • 1,522
  • 2
  • 22
  • 41
0

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;

miguel.de.icaza
  • 32,654
  • 6
  • 58
  • 76