我正在尝试为删除滚动视图中的视图设置动画。scrollView 的子视图是从对象数组中填充的。每个对象都有一个表示它的视图。有时我在删除时遇到 indexOutOfBounds 异常。这是我的删除代码:
-(void)deleteView:(UIView *)viewToDelete{
[self.myObjects removeObjectAtIndex:viewToDelete.tag];
[UIView animateWithDuration:0.5 animations:^{
viewToDelete.alpha = 0.0;
for (NSInteger index = viewToDelete.tag+1; index<self.myViews.count; index++){
UIView *view = [self.myViews objectAtIndex:index];
view.center = CGPointMake(view.center.x,view.center.y-viewToDelete.frame.size.height);
}
}]; completion:^(BOOL finished) {
[view removeFromSuperview];
}];
[self.myViews removeObjectAtIndex:viewToDelete.tag];
for (NSInteger index=0; index<self.myVies.count; index++){
UIView *view = [self.myViews objectAtIndex:index];
view.tag = index;
}
}