i am trying to implement curl effect by using below code snippet
curl down
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.95];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.view cache:YES];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
curl up
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.95];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];
but this works fine with portrait mode.
I want to implement it on landscape mode, taping on top right and bottom left.
currently its working in reverse effect.
Many Thanks
#import <QuartzCore/QuartzCore.h>
-(void)pageCurltoNextorPrevious:(UIView*)view:(int)identifier {
// Curl the image up or down
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.0];
CAMediaTimingFunction *fun=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[animation setTimingFunction:fun];
if (identifier==1){
//next animation
animation.type = #"pageCurl";
animation.subtype=#"fromRight";
animation.fillMode = kCAFillModeForwards;
animation.endProgress = 1.0; //0.58;
}
else {
//previous animation
animation.type = #"pageCurl";
animation.subtype=#"fromLeft";
animation.fillMode = kCAFillModeBackwards;
animation.startProgress = 0.0;
}
[animation setRemovedOnCompletion:NO];
//[view exchangeSubviewAtIndex:0 withSubviewAtIndex:2];
[[view layer] addAnimation:animation forKey:#"pageCurlAnimation"];
}
please,try this way.i used in view navigation by one View
1st view to go next Infoview i creat the curlup effect:
InfoView *objdb=[[InfoView alloc] initWithNibName:#"InfoView" bundle:nil];
[UIView beginAnimations:nil context:NULL ];
[UIView setAnimationCurve:UIViewAnimationTransitionCurlUp];
[UIView setAnimationDuration:1.0];
[self presentModalViewController:objdb animated:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[objdb release];
then back from infoview to main view then use this(curl down effect):
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationTransitionCurlDown];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self dismissModalViewControllerAnimated:YES];
[UIView commitAnimations];
i hope it's help for u.
Related
[baseview addSubview:textView1];
textView1.alpha = 0.0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:textView1 cache:YES];
textView1.alpha = 1.0;
[UIView commitAnimations];
[baseview addSubview:textView2];
textView2.alpha = 0.0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:textView2 cache:YES];
textView2.alpha = 1.0;
[UIView commitAnimations];
How i can animate between these two textviews.
Thanks for help
This should work to hide the first text view and show the second one:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:textView1 cache:YES];
{
textView1.alpha = 0.0;
textView2.alpha = 1.0;
}
[UIView commitAnimations];
Maybe you have to set the parent view as animation view (e.g. self.view).
i'm trying to flip two views in one screen with a single button click,i.e i want to have multiple animations at the same time(ex:iPhone music player where the button and view flips at the same time)
p.s-i don't want to animate views one after another,it should be done together
EDIT
this is the code i used,please help me out
[UIView beginAnimations:nil context:nil];
[UIView animateWithDuration:0.8 animations:^{
if (viewDisplay)
{
[fareView removeFromSuperview];
[containerView addSubview:mapView];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonView cache:YES];
viewDisplay = FALSE;
swapLabel.text = #"Fare View";
[mapOrFare setImage:[UIImage imageNamed:#"original_icon.png"] forState:UIControlStateNormal];
}
else
{
[mapView removeFromSuperview];
[containerView addSubview:fareView];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:containerView cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:buttonView cache:YES];
viewDisplay = TRUE;
swapLabel.text = #"Map View";
[mapOrFare setImage:[UIImage imageNamed:#"Map.png"] forState:UIControlStateNormal];
}
}];
[UIView commitAnimations];
Assuming that bgView1 and bgView2 are the views to be flipped, as below; you should just be able to put the animator code one after the other and it should all work out ok. See below for the example,
-(void)flipViews {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:bgView1 cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[bgView1 exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:bgView2 cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[bgView2 exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
}
Just use block animations, it should work with no issues.
[UIView animateWithDuration:myDuration
animations:^{
<animation 1 code>;
<animation 2 code>;
}];
I have the method:
- (void)blinkView:(UIView *)view
{
view.layer.opacity = 0.0f;
view.hidden = NO;
[UIView beginAnimations:#"Blinking" context:nil];
[UIView setAnimationRepeatCount:1.0];
[UIView setAnimationDuration:0.6f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
view.layer.opacity = 1.0f;
[UIView commitAnimations];
}
How can i write this code with blocks, and how i must implement method with reverse effect (hide uiview with blink) ?
[UIView transitionWithView: view
duration:0.6f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ view.layer.opacity = 1.0f; }
completion:NULL];
or
[UIView transitionWithView: view
duration:0.6f
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{ view.layer.opacity = 1.0f; }
completion:NULL];
You can set the repeat count by recursively calling the animation block (see here).
Hope it will help you.
You can use UIView's setAnimationDelegate: and setAnimationDidStopSelector:
[UIView beginAnimations:#"Blinking" context:nil];
[UIView setAnimationRepeatCount:1.0];
[UIView setAnimationDuration:0.6f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
view.layer.opacity = 1.0f;
[UIView commitAnimations];
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
// add your final code here : you can give new animation effect here.
}
Or try animateWithDuration (available only in iOS 4 or later)
[UIView animateWithDuration:0.6f
animations:^{
view.layer.opacity = 1.0f;
}
completion:^(BOOL completed){
// add your final code here : you can give new animation effect here.
}
];
I'm trying to call [[self navigationController] popViewControllerAnimated:YES] but making the animation slide right to left instead of left to right. Any easy way to do this? I want to return to the previous view. Any help is appreciated. Thanks!
This is how one can pop view controller in opposite direction. Its working for me 100%
CATransition *transition = [CATransition animation];
transition.duration = 0.45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionFromRight;
[transition setType:kCATransitionPush];
transition.subtype = kCATransitionFromRight;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popViewControllerAnimated:NO];
It is possible, look at the following code I used a while back and try to make it work for yourself. Yu only need to change the setAnimationTransition
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
There are a few different kind of default animations to use, apples site says this kind of animations are possible:
typedef enum {
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;
So in your case you would want to use the following:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController popViewControllerAnimated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
I am having a problem fading out my subview. I have no trouble fading the view in but fading out ..just drops the view.
-(void)flipToReview {
ReviewViewController *reviewVariable = [[ReviewViewController alloc] initWithNibName:#"ReviewViewController" bundle:nil];
[self setReviewViewController:reviewVariable];
self.ReviewViewController.view.alpha =0;
[UIView beginAnimations:#"flipview" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES];
[reviewVariable release];
[self.window addSubview:self.ReviewViewController.view];
self.ReviewViewController.view.alpha =1;
[UIView commitAnimations];
}
-(void)flipBackFromReview {
// self.ReviewViewController.view.alpha = 1;
[UIView beginAnimations:#"trip" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:NO];
self.ReviewViewController.view.alpha = 0;
[self.ReviewViewController.view removeFromSuperview];
[UIView commitAnimations];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
[self.ReviewViewController.view setHidden:1];
NSLog(#"remove subview");
}
Try the following:
[UIView animateWithDuration:3.0 delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{ ReviewViewController.view.alpha = 0.0;}
completion:^(BOOL fin) {
if (fin) [ReviewViewController.view removeFromSuperview];
}];
You need to move:
[self.ReviewViewController.view removeFromSuperview];
That cannot be done "over time" in an animation. What you want to do is move that to a selector and use setAnimationDelegate and setAnimationDidStopSelector. Put the following in your animation block:
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(finshedFadeOut)];
Then make the following method:
- (void)finshedFadeOut {
[self.ReviewViewController.view removeFromSuperview];
}
I had this issue as well, the way I got around it was changing the alpha to 0, instead of just removing the view. That can be animated.