我目前沮喪的問題,我似乎無法找到答案。我有一個由用戶控制的UIImageView,根據他們按的方向左右移動20個像素。同時,我正嘗試使用不同按鈕按下的NSArray對其進行設置。但是,每次我爲UIImageView設置動畫時,位置都會重置。iOS - 在動畫之後移動UIImageView重置爲原始位置,爲什麼?
例如,我會將它向右移動80像素,一旦按下動畫按鈕,它就會在動畫之前移回原始位置。這是非常令人憤怒的。這裏是我的代碼:
( 'POS' 是一個CGPoint設置爲(20,0)像素)
-(IBAction)moveleft {
player.center = CGPointMake(player.center.x-pos.x,player.center.y+pos.y);
}
-(IBAction)moveright {
player.center = CGPointMake(player.center.x+pos.x,player.center.y+pos.y);
}
-(IBAction)animove {
isMove = TRUE;
player.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"move0002.png"],
[UIImage imageNamed:@"move0003.png"],
[UIImage imageNamed:@"move0004.png"],
[UIImage imageNamed:@"move0005.png"],
[UIImage imageNamed:@"move0006.png"],
[UIImage imageNamed:@"move0007.png"],
[UIImage imageNamed:@"move0008.png"],
[UIImage imageNamed:@"move0009.png"],
[UIImage imageNamed:@"move0010.png"], nil];
player.animationDuration = 0.35;
player.animationRepeatCount = 1;
[player startAnimating];
}
總之,無論-(IBAction)moveleft
和-(IBAction)moveright
做工精細,一樣
-(IBAction)animove
,然而,一旦animove
被執行,UIImageView player
在左側或右側移動之前移回原始位置。
任何幫助/建議將不勝感激。
觀看斯坦福視頻15 - 可編輯文本,模態視圖控制器,您將獲得一切你想要的東西,但它爲一個標籤完成,你可以爲你的圖像視圖。下一個視頻16 - 核心運動,分段控制和警報--YouTube讓你一起做多個動畫。 – 2013-03-15 06:39:55
您可以顯示startAnimating的代碼,也可以解釋我們在哪裏設置了位置點 – Sandro 2013-03-15 09:57:12