簡體   English   中英

uiimageView動畫的問題:動畫停止

[英]Problem with uiimageView animation: animation stops

這是我的代碼:

-(void) createNewBall {

  UIImage * image = [UIImage imageNamed:@"bulle_03.png"];
  bulleBouge = [[UIImageView alloc] initWithImage:image];

  [bulleBouge setCenter:[self randomPointSquare]];
  [[self view] addSubview:bulleBouge];

}

-(void)moveTheBall{

  bulleBouge.center = CGPointMake(imageView.center.x + X, imageView.center.y + Y);

}

createNewBall每兩秒鍾調用一次。 我的問題是,創建的每個bulleBouge都會在兩秒鍾后停止移動。 我不知道為什么

請問該如何解決?

它停止移動b / cu每兩秒鍾初始化一次新的bulleBouge。 您也正在泄漏內存,因為您在分配新值之前從未松懈過它。 所以發生的事情是,在創建imageView之后,您僅保留對lasts實例的引用,因此只有最后一個實例正在更改位置。 要修復此問題,請將所有新的uiImageViews存儲在一個數組中,並在兩秒鍾后隨機移動它們。

-(void) createNewBall {

  UIImage * image = [UIImage imageNamed:@"bulle_03.png"];
  UIImageView *bulleBouge = [[UIImageView alloc] initWithImage:image];
  [bulleBouge setCenter:[self randomPointSquare]];

  [bulleBougeArray addObject:bulleBouge];

  [[self view] addSubview:bulleBouge];

  [bulleBouge release];

}

-(void)moveTheBall{

  for(int i=0; i< [bulleBougeArray count];i++){
    UIImageView *bulleBouge = [bulleBougeArray objectAtIndex:i];
    bulleBouge.center = CGPointMake(imageView.center.x + X, imageView.center.y + Y);
   }

}

塞浦路斯人是正確的。 以一種更簡單的形式,您每兩秒鍾在相同的變量下創建一個新的bulleBouge。 該程序已經有一個,但是由於您告訴它要在同一個ivar下創建一個新程序,因此它會忘記舊的程序,因此不會移動它。 您需要一個數組,以便可以分別記住每個球,並分別移動,如他發布的示例代碼所示。

暫無
暫無

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

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