gpt4 book ai didi

iOS:如何使用 UIButton 重新生成 UIImageView

转载 作者:行者123 更新时间:2023-11-29 02:43:09 26 4
gpt4 key购买 nike

我有一个非常简单的应用程序,有一个 UIImageView 和一个 UIButton。每次用户按下按钮时,图像将在 x 方向移动 -44 度,在 y 方向移动 -41 度。我的问题是:如何设置“if 语句”,以便当 UIImageView 到达屏幕中的某个点(可能是屏幕的末尾)时,它将在屏幕的其他点(可能是屏幕的开头)重新生成?

类似于:如果imageOne到达x点和y点,则在x点和y点重新生成imageOne。

这是我的代码:

文件。

{

IBOutlet UIImageView *ImageOne;

}

-(IBAction)Button:(id)sender;

文件。米

-(IBAction)Button:(id)sender{


//ImageOne moving down the screen

[UIView animateWithDuration:0.1f
animations:^{

ImageOne.center = CGPointMake(ImageOne.center.x -44, ImageOne.center.y +41);

}];

我需要在我的代码中实现什么?

如有任何帮助,我们将不胜感激!

提前致谢!

最佳答案

我认为您不需要为您的目的使用“animateWithDuration”。

假设您有 imageOne 并在 x 方向向左移动它,当图像移出屏幕,你想让它移回屏幕中间。试试这个

-(IBAction)Button:(id)sender{
//reset image onto screen.
if(imageOne.center.x < 0){
imageOne.center = CGPointMake(200, imageOne.center.y);

}

//move image left
imageOne.center = CGPointMake(imageOne.center.x-44, imageOne.center.y);
}

关于iOS:如何使用 UIButton 重新生成 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25496451/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com