Changing animation's center and angle - iphone

Is it possible to set a new center and an angle to an animation?
I'm trying to build an animation to curl a page but just partially but by default this effect curls the page from bottom right to upside left.
Here is a chunk of the code I'm using to animate this.
- (IBAction)curlUp{
// Curl the image up or down
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:0.35];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
if (!curled){
animation.type = #"pageCurl";
animation.fillMode = kCAFillModeForwards;
animation.endProgress = 0.78;
} else {
animation.type = #"pageUnCurl";
animation.fillMode = kCAFillModeBackwards;
animation.startProgress = 0.42;
}
[animation setRemovedOnCompletion:NO];
[[self view] exchangeSubviewAtIndex:4 withSubviewAtIndex:5];
[[[self view] layer] addAnimation:animation forKey:#"pageCurlAnimation"];
// Disable user interaction where necessary
if (curled) {
[[self view] exchangeSubviewAtIndex:4 withSubviewAtIndex:5];
[[[[self view] subviews] lastObject] removeFromSuperview];
} else {[self.view addSubview:ofertasCompraViewController.view];
[self.view bringSubviewToFront:self.view];
//[self.navigationController.navigationBar setUserInteractionEnabled:YES];
//[self.view setUserInteractionEnabled:YES];
}
curled = !curled;
}
The end progress sets where the page will stop curling and now I would like to set in which direction the view will curl.
Thanx!

Finally I found a solution to my problem a couple of days after asking in here. I'm going to post the code I used so that anybody can check it. Maybe it will be useful for somebody else!
// Curl the image up or down
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:0.35];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
if (!curled){
animation.type = #"pageCurl";
animation.fillMode = kCAFillModeForwards;
animation.subtype = kCATransitionFromLeft;
animation.endProgress =0.75;
} else {
animation.type = #"pageUnCurl";
animation.fillMode = kCAFillModeBackwards;
animation.subtype = kCATransitionFromLeft;
animation.startProgress = 0.42;
}
[animation setRemovedOnCompletion:NO];
if(cambioVista)
[[self view] exchangeSubviewAtIndex:4 withSubviewAtIndex:5];
[[[self view] layer] addAnimation:animation forKey:#"pageCurlAnimation"];

Sorry, I can't help you with this but I've seen a number of threads on this type of animation, and apple is keen to reject apps that are using this code as they are 'using private APIs'. See this thread on the apple forums.

Related

Partial Curl get dissapears when home button clicks

I am doing a partial curl using CATransition, It works fine but After home button click while the page is curved and trying to resume then the curved page gets disappear.
Here is my code
self.animation = [CATransition animation];
[self.animation setDelegate:self]; [animation setDuration:1.00];
[self.animation setTimingFunction:UIViewAnimationCurveEaseInOut];
if (!curled){
self.animation.type = #"pageCurl";
self.animation.fillMode = kCAFillModeForwards;
self.animation.endProgress = 0.50;
}
[self.animation setRemovedOnCompletion:NO];
[[self view] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[[[self view] layer] addAnimation:self.animation forKey:#"pageCurlAnimation"];
This may help you
-(void)viewWillDisappear:(BOOL)animated{
[self.view.layer removeAllAnimations];
[super viewWillDisappear:YES];
}

How to move the uiview part of the screen from right to left using CATransition

I am developing one application.In that i want to move the uiview from right to left using below code.
-(void)centerAnimation1:(id)sender
{
theview=qstnview;
CATransition *animation = [CATransition animation];
animation.delegate = self;
[animation setDuration:0.4];
[animation setType:kCATransitionMoveIn];
if(rhtolft)
{
[animation setSubtype:kCATransitionFromLeft];
}
else
{
[animation setSubtype:kCATransitionFromRight];
}
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
//[animation setanima]
[[theWindow layer] addAnimation:animation forKey:#"SwitchToView1"];
[[theview layer] addAnimation:animation forKey:#"SwitchToView1"];
[qstnview removeFromSuperview];
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if(animate)
{
CATransition *animation = [CATransition animation];
animation.delegate = self;
[animation setDuration:0.4];
[animation setType:kCATransitionMoveIn];
if(rhtolft)
{
[animation setSubtype:kCATransitionFromLeft];
rhtolft=NO;
}
else
{
[animation setSubtype:kCATransitionFromRight];
}
//[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
//[animation setanima]
[[theview layer] addAnimation:animation forKey:#"SwitchToView1"];
[self.view addSubview:qstnview];
}
}
But this one is moving the view from right side last edge to left side.But i need to move within the frame size only.I dont need to start from right side edge.So please tell me how to do that one.
EDIT:
[UIView animateWithDuration:0.33f
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
[theView setFrame:newFrame]; //set new frame for view where x =200;
}
completion:^(BOOL finished){
// do whatever post processing you want (such as resetting what is "current" and what is "next")
}];
The screen from right to left using CATransition like this
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theView layer] addAnimation:animation forKey:#"rightToLeftAnimation"];
Use this code for changing images with animation:
CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype=kCATransitionFromLeft;
[yourImageViewName.layer addAnimation:transition forKey:nil];
I dont think you need to dive down to CA to do this kind of thing. It can be done using UIView animations. Here http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial is a good tutorial on UIView animations.

troubles with animation

I have a little problem, I have a viewcontroller with a webview and some button, I want to apply to webview a curl animation and see instad webview the view if the same controller.
like this
instead this
in the first case I use webview.hidden = YES but when I try to came back the view is (obviusly) hidde, if I put webview.hidden = NO on the method for come back I get this
any solution?
this is my code:
- (IBAction)toggleView:(id)sender {
CATransition *animation = [CATransition animation];
[animation setDelegate:self.view];
[animation setDuration:0.7];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = #"pageCurl";
animation.fillMode = kCAFillModeForwards;
animation.endProgress = 0.7;
[animation setRemovedOnCompletion:NO];
[[self.vistaWeb layer] addAnimation:animation forKey:#"pageCurlAnimation"];
}
- (IBAction) torna {
CATransition *animation = [CATransition animation];
[animation setDelegate:self.view];
[animation setDuration:0.7];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = #"pageCurl";
animation.fillMode = kCAFillModeBackwards;
animation.startProgress = 0.7;
animation.endProgress = 0;
[animation setRemovedOnCompletion:NO];
[[self.vistaWeb layer] addAnimation:animation forKey:#"pageCurlAnimation"];
}

CATransition page curl from top

I wanted to know if anyone managed a pagecurl from the top using the CATRANSITION. I have the following :
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:0.35];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = #"pageCurl";
animation.subtype = kCATransitionFromTop;
animation.fillMode = kCAFillModeForwards;
animation.endProgress = 0.30;
[animation setRemovedOnCompletion:NO];
[self.view.layer addAnimation:animation forKey:#"pageCurlAnimation"];
but unfortunately, it always does the page curl from the bottom. I will be very grateful if anyone can tell me how to do a page curl from the top.
Many thanks.
I've got this working. You need to set animation.type = #"pageUnCurl"; - who would have thought! Thanks apple.
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
animation.type = #"pageUnCurl";
animation.subtype = kCATransitionFromTop;
animation.fillMode = kCAFillModeForwards;
animation.startProgress = 0.3;
[animation setRemovedOnCompletion:NO];
[self.helpView.layer addAnimation:animation forKey:#"pageCurlAnimation"];
Found the answer, need to set subtype to from right!
subtype = KCATransitionFromLeft or KCATransitionFromRight
you can also remove the animation.endProgress if you want a total animation of curl page .
=)

Partial page curl animation

I have a working transition using UIViewAnimationTransitionCurlUp however, I would like the animation to stop halfway through, much like the Maps application...Any thoughts on how to achieve this?
In iOS 3.2 and later, you can give your UIViewController a UIModalTransitionStyle of UIModalTransitionStylePartialCurl. From the UIViewController reference, we see
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
So an example use case would be:
UIViewController *viewController;
// …create or retrieve your view controller…
// Note: The modalPresentationStyle must be UIModalPresentationFullScreen,
// and the presenter must also be a full-screen view
viewController.modalPresentationStyle = UIModalPresentationFullScreen;
viewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
I found a solution to add an UIView to UIViewController using Animation block.
m_Container is an UIView who contain my view animation (self).
self is an UIView.
CAUTION : You need to have import QuartzCore
To present view with page curl animation you can use :
-(void)PresentView
{
[UIView animateWithDuration:1.0
animations:^{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:0.7];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = #"pageCurl";
animation.fillMode = kCAFillModeForwards;
animation.endProgress = 0.65;
[animation setRemovedOnCompletion:NO];
[m_container.layer addAnimation:animation forKey:#"pageCurlAnimation"];
[m_container addSubview:self];
;}
];
}
And when you want hide this view you can use :
-(void)HideHelpView
{
[UIView animateWithDuration:1.0
animations:^{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:0.7];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = #"pageUnCurl";
animation.fillMode = kCAFillModeForwards;
animation.startProgress = 0.35;
[animation setRemovedOnCompletion:NO];
[m_container.layer addAnimation:animation forKey:#"pageUnCurlAnimation"];
[self removeFromSuperview];
;}
];
}
The Maps partial curl is a private API. You can find details of how to use it in Erica Sadun's book The iPhone Developer's Cookbook, but you will get rejected from the App Store for using it.
Not sure if this will work, but the parameter to +setAnimationRepeatCount: can be a fraction.