Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top