PageTurn animation in iPhone - iphone

How to make page turn animation like the Stanza app ?
Earlier i was using , but its not the animation i am looking for.
[CATransaction begin];
CATransition *animation = [CATransition animation];
[animation setType:(prevPage ? #"pageUnCurl" : #"pageCurl")];
[animation setDuration:0.7f];
[animation setFillMode: ( prevPage ? kCAFillModeBackwards : kCAFillModeForwards )];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[[self layer] addAnimation:animation forKey:#"transitionViewAnimation"];
[CATransaction commit];
Thanks

[UIView beginAnimations:#"yourAnim" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:yourView cache:cacheFlag];
...
[UIView commitAnimations];
This does the page curl animation. For the flip, use the UIViewAnimationTransitionFlipFromLeft or UIViewAnimationTransitionFlipFromRight constant.

Related

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?
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"];
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) {
}
];
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
Code on GitHub
Implement Changes Between Two Views In iPhone
add subview with animation
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.

Cannot make a smooth animation in UIView

I have add a view animation to my view on button click, the view will slide to right side on first click and will come back on second click..(just like in Facebook iPhone app)
But the animation is not so smooth, there are some jerkings and all. But when it reaches the final (x, y) they are in correct position, when the view is moving the animation doesn't look so professional.Help me to correct this
and one question,is there any way to animate the below tabbar with the same event.
(You can see in images that the tabbar is not moved with animation)
Adding the code here!
- (IBAction)ShowView:(id)sender
{
if (n==0)
{
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
self.view.center = CGPointMake(410, 205);
[[self.view layer] addAnimation:animation forKey:#"SwitchToNoti"];
n=1;
}else
{
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
self.view.center = CGPointMake(160,205);
[[self.view layer] addAnimation:animation forKey:#"SwitchTohome"];
n=0;
}
try this
- (IBAction)ShowView:(id)sender {
if (n==0)
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view setCenter:CGPointMake(self.view.center.x + 100, self.view.center.y)];
[UIView commitAnimations];
n=1;
}else
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view setCenter:CGPointMake(self.view.center.x - 100, self.view.center.y)];
[UIView commitAnimations];
n=0;
}
}
You can use the following code to show the animation :-
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.40];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.view.frame = TestRect;
[UIView commitAnimations];
You need to make a CGRect named TestRect here and see if this solves your problem.

I want to animate an UIImageView & during animation I want to recognize event on it

When am animating a UIImageView it doesn't send event during it is animating, but when it finishes its animation, that time it is able to send event, I'v tried UIButton too.
You just need to include the UIViewAnimationOptionAllowUserInteraction option when invoking the animation:
[UIView animateWithDuration:animationDuration
delay:0
options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
<snip>];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.0];// try 0.1 also
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[yourImageView layer] addAnimation:animation forKey:#"transitionViewAnimation"];//Try self.view insted of yourImageView if you want to animate whole view

CATransition not animating from method inside UIView subclass

I have a method inside my UIView subclass which adds a to CATransition its layer:
- (void)animateWithDefaultTransition:(NSString *)transition duration:(CFTimeInterval)duration
{
CATransition *animation = [CATransition animation];
[animation setType:transition];
[animation setDuration:duration];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setSubtype:#"fromRight"];
[zoomView setHidden:NO];
[[self layer] addAnimation:animation forKey:nil];
}
I call it from another class like this:
[transitionView animateWithDefaultTransition:#"push" duration:1.0];
However zoomView simply appears and the transition isn't performed.
Try the UIView transition method:
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[fromView removeFromSuperview];
[containerView addSubview:toView];
}
completion:NULL];

UIButton move animated problem

how to make a UIButton when moving (animated) without shadow? i tried the code but cannot make it can someone modifify or point out the problem
-(IBAction)move{
point=CGPointMake(0,1);
for(int i=0;i<50;i++){
NSLog(#"fdfafa");
CATransition *animation = [CATransition animation];
[animation setType:#"push"];
[animation setSubtype:#"fromBottom"];
[animation setDuration:0.5];
//[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[testButton.layer addAnimation:animation forKey:kAnimationKey];
testButton.center = CGPointMake(testButton.center.x, testButton.center.y + point.y);
}
NSLog(#"%f",testButton.center.y);
}
or have other better method to make a object move animated?
I'd use something like this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
button.center = CGPointMake(x,y);
[UIView commitAnimations];