简体   繁体   English

自动调整大小和UIImageView无法正常工作

[英]Autosize and UIImageView not working properly

I have an UIImageView located at the bottom right side of the screen that moves a few points to the left each time the user presses a button. 我在屏幕的右下角有一个UIImageView,每次用户按下按钮时,它都会向左移动一些点。 When the image reaches the other side of the screen I used an if statement to place it back at the right side. 当图像到达屏幕的另一侧时,我使用了if语句将其放回右侧。 I have auto layout off and Autosizing with these options: 我关闭了自动布局并使用以下选项自动调整大小: 在此处输入图片说明

So it can work for both, 3.4 inch display and 4 inch display. 因此,它既可以用于3.4英寸显示屏,也可以用于4英寸显示屏。

The first time around the image moves from right to left the way its supposed to in both screens. 图像周围的第一次图像在两个屏幕中都从右移到左移。 But when it reaches the end and reappears back at the beginning it only works for 4 inch display. 但是,当它到达末尾并重新出现在开头时,仅适用于4英寸显示屏。 In the 3.5 inch display the image is off the screen because for some reason is not recognizing the Autosizing options anymore. 在3.5英寸显示屏中,由于某些原因无法识别“自动调整大小”选项,因此图像不在屏幕上。

My question is: Is there a way to set an if statement that says something like this? 我的问题是:有没有办法设置一个if语句,像这样?

if (3.5 inch display) {
ImageOne.center = CGPointMake(400,300);
} else {
  ImageOne.center = CGPointMake(300,400);
}

I imagine this way could be the solution to show the image properly in both screens, if not how can i fix it? 我想这种方式可能是在两个屏幕上正确显示图像的解决方案,如果没有的话我该如何解决?

Any help would be greatly appreciated since I been trying to fix this all day. 自从我整天试图解决此问题以来,任何帮助将不胜感激。

Thank you in advance! 先感谢您!

Try this 尝试这个

if ([[UIScreen mainScreen] bounds].size.height == 568)){
    //4 inch
    ImageOne.center = CGPointMake(300,400);

}
else{

    ImageOne.center = CGPointMake(400,300);

}

This will be work only on one condition that is uncheck "Use Auto Layout". 仅在取消选中“使用自动版式”的一种情况下才可以使用此功能。

for that Go to the File inspector in interface builder, and untick "Use Auto Layout 为此,请转到界面构建器中的文件检查器,然后取消选中“使用自动布局 取消选中自动布局

i hope this will work for you.. 我希望这对您有用。

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

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