0

I am adding a view (lets say redView) to self.view in a view controller.

Now the problem is i want the page curl down animation when the redView is added.

Is it possible to get that ?

Sampath
  • 39
  • 8
  • 1
    Google for *addSubview animated*, first result is [this](http://stackoverflow.com/questions/2337408/addsubview-animation). – lawicko Feb 08 '12 at 10:05
  • @lawicko : Thanks for the link. I want the redView to curlDown on adding to self.view . – Sampath Feb 08 '12 at 10:11

2 Answers2

1

Sampath,

I do this in an app I am developing at the moment.

This is what I did and it works fine:

[self.view insertSubview:redView atIndex:0]

[UIView transitionWithView:self.view 
                  duration:1.0 
                   options:UIViewAnimationOptionTransitionCurlDown 
                animations:^{ [[[self.view subviews] objectAtIndex:1] removeFromSuperview];} 
                completion:NULL];

Hope it works for you.

Keith

1

if redView is subClass of UIViewController.

First method

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
                       forView:redView.view
                         cache:YES];

[self.view addSubview:redView.view];
[UIView commitAnimations];

Second Method

RedView *viewController = [[RedView alloc] initWithNibName:@"RedView" bundle:nil];
    [viewController setModalTransitionStyle:UIModalTransitionStylePartialCurl];
    [self presentModalViewController:viewController animated:YES];

if redView is subClass of UIView.

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
                       forView:redView
                         cache:YES];

[self.view addSubview:redView];
[UIView commitAnimations];
Krrish
  • 2,256
  • 18
  • 21
  • These seem a bit complicated to me, and I think beginAnimations and commitAnimations have been deprecated in favour of block animation as I used in my answer. – Keith at Ideal Films Feb 08 '12 at 10:42
  • 1
    Its not depreciated, it says discouraged in ios 4 nd later – Krrish Feb 08 '12 at 10:45
  • @Krrish: Thanks a lot for the answer. The answer i need is "if redView is subClass of UIView". I tried it . It first shows the view and then performs the animation. I want it like perform animation and then show the view. That is because self.view contains some data and redView contains some other data. User has to feel the change in data on animation. – Sampath Feb 08 '12 at 14:04
  • @Krrish : The image is like http://stackoverflow.com/questions/2551521/is-it-possible-to-get-a-catransition-animation-as-uiimage – Sampath Feb 08 '12 at 14:12
  • @Sampath , I am not sure what exactly ur need is. In the third line of the code Just pass cache:NO instead of cache:YES, then the data in the view will start loading while animating page curl. – Krrish Feb 09 '12 at 05:59