Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

addSubview animation

I have main UIView where I display different data. Then I put a button, which displays subview like this:

- (IBAction) buttonClicked:(id)sender {     UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(25,25,50,20)];     UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(25,25,50,25)];     newLabel.text = @"some text";     [newView addSubview:newLabel];      [self.view addSubview:newView];     [newLabel release];     [newView release]; } 

newView appears fine, but it doesn't animate itself any way, it just appears immediately. How can I add some kind of animation when newView appears? Like zoom or slide down or something like that. Is there some simple code?

like image 737
Mike Avatar asked Feb 25 '10 20:02

Mike


2 Answers

[UIView transitionWithView:containerView duration:0.5         options:UIViewAnimationOptionTransitionCurlUp //change to whatever animation you like         animations:^ { [containerView addSubview:subview]; }         completion:nil]; 
like image 116
adedoy Avatar answered Sep 18 '22 20:09

adedoy


Hi You could use the UIView Animations:

[newView setFrame:CGRectMake( 0.0f, 480.0f, 320.0f, 480.0f)]; //notice this is OFF screen! [UIView beginAnimations:@"animateTableView" context:nil]; [UIView setAnimationDuration:0.4]; [newView setFrame:CGRectMake( 0.0f, 0.0f, 320.0f, 480.0f)]; //notice this is ON screen! [UIView commitAnimations]; 

The SDK will now figure this out for you and animate the view to the positions you gave it. This works for most properties of UIViews: alpha, scale, bounds, frames, etc.

There are also build in animations as flip and curl:

[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight                            forView:newView                             cache:YES];  [self.navigationController.view addSubview:settingsView.view]; [UIView commitAnimations]; 

Hope this helps out getting you started:)

like image 23
RickiG Avatar answered Sep 19 '22 20:09

RickiG