簡體   English   中英

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

[英]iOS: How to regenerate UIImageView with UIButton

我有一個非常簡單的應用程序,它具有UIImageView和UIButton。 每次用戶按下按鈕時,圖像將在x方向上移動-44,在y方向上移動-41。 我的問題是:如何設置“ if語句”,以便當UIImageView到達屏幕中的某個點(可能是屏幕的末尾)時,它將在屏幕的其他點(可能是屏幕的開始)處重新生成。 ?

像這樣:如果imageOne到達x點和y點,則在x點和y點重新生成imageOne。

這是我的代碼:

文件。 H

{

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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM