複数のオブジェクトが作成され、ボタンがクリックされると最初に作成されたオブジェクトが最初に削除されるという考え方です。たとえば、オブジェクト # 1、2、3 の順に作成し、最初にボタンをクリックすると、最初に 1、2、3 の順に削除されます。
配列内のアイテムを作成するための私のコードは次のとおりです。
//array of imageviews
aryImages= [[NSMutableArray alloc] init];
//creation code for the images
CGRect frame = CGRectMake(480, 180, 60, 55);
imgViewPicture = [[UIImageView alloc] initWithFrame:frame];
imgViewPicture.image=[UIImage imageNamed:@"flower.png"];
[self.view addSubview:imgViewPicture];
[aryImages addObject:imgViewPicture];
次に、ここに移動コードがあります
for (int x = 0; x < [aryImages count]; x++) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[imgViewPicture setFrame:CGRectMake(120, 180, 60, 55)];
[UIView commitAnimations];
}
特定の x 位置を超えてアイテムを削除するためのコードは次のとおりです。
for (int x = 0; x < [aryImages count]; x++) {
UIImageView *imgViewInQuestion = (UIImageView *)[aryImages objectAtIndex:x];
if (imgViewInQuestion.frame.origin.x>=120) {
[aryImages removeObjectAtIndex:x];
}
}
残念ながら、これは機能しません。理由や考えられる解決策はありますか?