hacker
hacker

Reputation: 8947

How to add a subview with a presentmodalview type animation?

I have an application in which I need to

add a subview to a view with presentmodalview type animation

But in

CATransition

I didn't find any type of transition like that. Also in

UItransitionstyle

Can anybody guide me on this?

Upvotes: 0

Views: 306

Answers (4)

Adithya
Adithya

Reputation: 4705

If you only want to use CATransition

CATransition *animation = [CATransition animation];
[animation setType:kCATransitionMoveIn];
[animation setSubtype:kCATransitionFromTop];
[animation setDuration:0.6f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                              kCAMediaTimingFunctionEaseInEaseOut]];
[subview.layer addAnimation:animation forKey:@"someTransition"];

Upvotes: 1

Kapil Choubisa
Kapil Choubisa

Reputation: 5232

Try to use UIView animation block:

yourView.frame = CGRectMake(0, yourSuperView.frame.size.height, yourView.frame.size.width, yourView.frame.size.height);
[yourSuperView addSubview:yourView];
[UIView animateWithDuration:1.0 animations:^{
    yourView.frame = CGRectMake(0, 0, yourView.frame.size.width, yourView.frame.size.height);
} completion:^(BOOL finished) {
    //Task to do on Animation completion.
}];

You change the animation duration according to your convince. Also you can use following:

[UIView animateWithDuration:1.0 animations: {
      //your Implemntation
}];

or

[UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationCurveEaseIn animations:^{
    
} completion:^(BOOL finished) {
    
}];

Please check the UIView class reference for animation option in UIViewAnimationOptions section and detail of methods.

Upvotes: 1

jamil
jamil

Reputation: 2437

Try this code

[self.view bringSubviewToFront:yoursubview];
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionFade];
[animation setDuration:1.00];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                              kCAMediaTimingFunctionEaseIn]];
[yoursubview.layer addAnimation:animation forKey:@"fadeTransition"];

For more info check these links

  1. Code on GitHub
  2. Implement Changes Between Two Views In iPhone
  3. add subview with animation

Upvotes: 1

Venk
Venk

Reputation: 5955

Change the frame of the subview insite the UIView Animation, like as follows,

initially set the

subView.frame=CGRectMake(0,self.view.frame.size.height,your_width,your_height);

then set the required frame position inside the animation

[UIView animateWithDuration:0.25 delay:0 options: UIViewAnimationCurveEaseOut animations:^ {

        // set subView's frame

    } completion:^(BOOL finished) {

    }
     ];

Upvotes: 1

Related Questions