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?
The Frame property is a value type, this means that if you do:
what you are actually doing is:
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;
// The Code is quite simple and self explanatory
By using >dispatch_async(dispatch_get_main_queue(), ^{ I made the code to run in the main queue, not in the background.
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;