views:

216

answers:

1

Hey,

I've setup an own class(custom UIView). I'am adding two of these customViews to my UIView as subviews. So now the question araises: How do I animate the subviews?

myCustomView *myCustomViewInstance = [[myCustomView alloc] initWithText:@"myText"]];
    [self.viewContainer addSubview:myCustomViewInstance];

myCustomView *myCustomViewInstance2 = [[myCustomView alloc] initWithText:@"myText2"]];
    [self.viewContainer addSubview:myCustomViewInstance2];

Normally I would animate uiviews with:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
self.viewContainer = CGRectMake(20,20,320,460);
[UIView commitAnimations];

In this case that doesn't work because I am animating the view not the subviews. I also can not acess the subviews directly because of the local declaration. Any Ideas?

Thanks a lot!

+1  A: 

You can set a tag (an integer) on your subviews and retrieve them again with [self.viewContainer viewWithTag:]. Then animate as you do with the viewContainer.

Johan Kool
thanks works great :)To add multiple Subviews whcih is the best way?
rdesign