这个想法是创建多个对象,当单击按钮时,第一个创建的对象将首先被删除,依此类推。例如,它会创建对象#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];
}
}
不幸的是,这不起作用。对我有什么想法或可能的解决方案吗?