Partial Curl get dissapears when home button clicks - iphone

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];
}

Related

Animation lag at the first run

The search bar is animated using the following code:
- (IBAction)toggleSearchBar:(UIBarButtonItem *)sender{
CATransition *applicationLoadViewIn = [CATransition animation];
[applicationLoadViewIn setDuration:0.2];
[applicationLoadViewIn setType:kCATransitionPush];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
if (self.searchBar.hidden) {
self.searchBar.hidden = NO;
[self.searchBar becomeFirstResponder];
[applicationLoadViewIn setSubtype:kCATransitionFromBottom];
[[searchBar layer] addAnimation:applicationLoadViewIn forKey:kCATransitionPush];
}else{
self.searchBar.hidden = YES;
[self.searchBar resignFirstResponder];
[applicationLoadViewIn setSubtype:kCATransitionFromTop];
[[searchBar layer] addAnimation:applicationLoadViewIn forKey:kCATransitionPush];
}
}
It works fine except the lag at the first run of the animation. Is there anyway to fix it? Any help will be appreciated:)
Edit 1
he leftBarButton is wired to toggleSearchBar: action. The app is loaded. The first animation is the first time the leftBarButton clicked.
Why don't you show it off screen on loading the view controller... it's a bit hacky but it should do the trick.

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];

switching two views causes crash

XYZAppDelegate *appdelegate=[[UIApplication sharedApplication] delegate];
CSelectorViewController *cPrice=[[CSelectorViewController alloc] initWithNibName:#"CSelectorViewController" bundle:nil];
[cPrice.view setFrame:CGRectMake(0, 20, 320, 480)];
[appdelegate.window addSubview:cPrice.view];
[self applyAnimation];
[cPrice release];
i am adding a view like this,not using navigationcontroller,since i have to switch two views top-bottom also.but when i am giving the [cPrice release]; the app crashes. but when i am not giving it in code... the static analyser is showing a warning..what is the right way to do this?
-(void)applyAnimation
{
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
XYZAppDelegate *appdelegate=[[UIApplication sharedApplication] delegate];
[[appdelegate.window layer] addAnimation:animation forKey:#"slideLeft"];
}
You're adding the view of cPrice to the window as a subview (which will implicitly retain the view), but you do nothing to preserve cPrice itself. You should make it a retained property or some such.

Changing animation's center and angle

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.

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.