简体   繁体   English

移动视图并更改uiimageview的图像不会执行视图的移动

[英]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. 我有一个非常简单的情况:在一个视图中,我有一个UIImageView和一个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. 在某个时刻,我想更改标签的位置,并以相同的方法更改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? 或针对此问题的有效解决方法?

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: 现在有了iOS6,每当我看到有关通过代码完成后似乎对frame坐标的更改似乎无法正常工作的帖子时,我立即怀疑自动布局设置:

在此处输入图片说明

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! 很高兴您解决了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM