Take the 2-minute tour ×

I have a screen which contains several subviews. On the user's interaction, I want to add another subview, change the positions of the other subviews, and make them disappear at the same time. My code is:

[self.view addSubview:imageView];
[UIView animateWithDuration:0.3
                     for (UIView *currentItemView in self.currentItemViews) {
                         currentItemView.center = someCenter;
                         currentItemView.alpha = 0;
                 } completion:^(BOOL finished) {


Before I added the code with the new subview everything worked fine, but now the only thing is animated is the setting of alpha. The subviews don't move. Any idea why and how to solve this?

Thanks in advance!


The code for creating the currentItemViews array:

self.currentItemViews = [[NSMutableArray alloc] initWithCapacity:6];
for (Item *item in arrayOfItems) {
    ItemView *itemView = [[NSBundle mainBundle] loadNibNamed:@"ItemView" owner:self options:nil].lastObject;
    itemView.item = item;
    [self.currentItemViews addObject:itemView];
    [self.view addSubview:itemView];

The ViewController I'm in, is a childViewController to another one, so it's view is added as subview too. Could that be the problem?

share|improve this question
Looks like it should be okay to me - did you verify that your someCenter value is different than the currentItemView.center? –  Mike M Dec 27 '12 at 13:38
Yepp. If I comment that first line of code ([self.view addSubview:imageView];), it works as expected. And I can switch that imageView to a blank UIView, it causes the same problem. –  Levi Dec 27 '12 at 13:46
This is interesting, I just tested your code and it works fine even if imageView is nil. Can we see the code for how self.currentItemViews is configured. –  0x7fffffff Dec 27 '12 at 13:56
The child view controller thing makes my head hurt. :-P I'd check what the value of "center" is, and what the value of the superview's "bounds" is and see if those are valid values. –  Mike M Dec 27 '12 at 14:16
The centers, bounds and frames seem to be ok. I inserted a breakpoint in the animation block after the for and in the completion block. In the animation block the frames are changed for the subviews, but in the completion block they are being reset to the original frames. –  Levi Dec 27 '12 at 14:29
show 1 more comment


Your Answer



Browse other questions tagged or ask your own question.