alinoz
alinoz

Reputation: 2822

Moving a view and changing the image of uiimageview is not performing the move of the view

I have a very simple situation: in a view i have an UIImageView and one UILabel. at a moment in time I want to change the position of the label and in the same method to change the image of the uiimageview.

self.myLabel.center = CGPointMake(158, 230);
self.myImageView.image = [UIImage imageNamed:@"anotherImage.png"];

But this code will change only the image and will not move the label. If i comment out the second line and run the code then the label will change the position.

Dose anybody have an idea why is not working? Or a valid workaround for this problem?

Upvotes: 0

Views: 577

Answers (1)

Rob
Rob

Reputation: 438467

I just tested the above code and it works fine. When the keyboard pops up, label moves and image changes fine. The issue in your program has to be something simple, but it isn't the above code.

Now that we've got iOS6, whenever I see posts about changes to frame coordinates not seeming to behave properly when done via code, I immediately suspect the Autolayout settings:

enter image description here

Make sure you uncheck that, because otherwise constraint based logic will override any attempts to manually adjust settings via code. (Or, if you want to use Autolayout, rather than setting frame coordinates, programmatically adjust your constraints to achieve the desired result.)

Anyway, it sounds like that was you issue. Glad you solved it!

Upvotes: 3

Related Questions