How can we animate the ipad view like a book - ipad

I want to animate the view in ipad like a book, view should be turned like a page from right to left and vice versa. Can anyone provide me any tutorial or example for this.
Thanks in advance.

You want to use the UIPageViewController
See e.g. this tutorial

CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.0f];
animation.startProgress = 0.2;
animation.endProgress = 1;
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
[animation setType:#"pageCurl"];
[animation setSubtype:kCATransitionFromLeft];
[animation setFillMode: kCAFillModeBackwards];
[self.view.layer addAnimation:animation forKey:#"animation"];
for flipping the other way you make :
[animation setType:#"pageUnCurl"];
Hope this helps, good luck :)

check link
UIPageViewController

Related

How to create UIView ripple circle animation?

I want to create UIView Animation like this link
css3 ripple effect example
i have tried all these codes in ViewDidLoad() and not working
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 100, 100)];
view.backgroundColor = [UIColor blueColor];
CATransition *animation=[CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.75];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
[animation setType:#"rippleEffect"];
[animation setFillMode:kCAFillModeRemoved];
animation.endProgress=1;
[animation setRemovedOnCompletion:NO];
[view.layer addAnimation:animation forKey:nil];
[self.view addSubview:view];
i want to create the same thing in iOS .Please help me
The following lines of your code looks fine:
CATransition *animation=[CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.75];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
[animation setType:#"rippleEffect"];
[view.layer addAnimation:animation forKey:nil];
But, the problem is that your applying the animation before adding the view to its superview. which obviously will not work!
Try, to add the subview then apply the animation. I also expect that this will not work.
if you are adding this view to its superview in the viewDidLoad method. apply the animation in the ViewDidAppear or ViewWillAppear methods.
Otherwise, create a separate method that applies the animation. and call it after you add the subview by calling performSelector:withObject:afterDelay method.
Hope this helps you Sample class
UIView+Glow is a category on UIView that adds support for making views glow (useful for highlighting a part of the screen to encourage the user to interact with it).
To learn what it can be used for, and how to use it, check out the blog post

UILabel's layer doesn't update color while animating

I am animating a UILabel to 'evaporate' off the screen using CATransition.
I want the label text to turn green, and move off the screen.
The following code does 'evaporate' the label fine, but doesn't change its colour before animating:
CATransition *transition = [CATransition animation];
transition.beginTime = CACurrentMediaTime();
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
[self.displayLabel.layer addAnimation:transition forKey:#"evaporate"];
self.displayLabel.textColor = [self greenColor];
self.displayLabel.text = #" ";
Calling setNeedsDisplay on the label doesn't work.
Can't use a CABasicAnimation because the label text is changing.
What am I doing wrong and how do I fix it?
You basically want nested animations or, in a sense, looking for a completion block type thing.
The closest I can think of achieving this is by using the CATransition delegate
Example:
-(IBAction)btnTest:(UIButton *)sender
{
//[1] Animate text color change
CATransition *animation = [CATransition animation];
[animation setDelegate:self]; //important
[animation setRemovedOnCompletion:YES]; //better to remove the animation
[animation setBeginTime:CACurrentMediaTime()]; //not really needed
[animation setDuration:0.4];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[animation setType:kCATransitionFade];
//you can specify any key name or keep it nil. doesn't make a difference
[self.displayLabel.layer addAnimation:animation forKey:#"changeTextColor"];
[self.displayLabel setTextColor:[UIColor greenColor]];
}
#pragma mark - CATransition Delegate
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
//[2] Animate text sublayer
/*
The following CATransition should not set a delegate
otherwise this animation will loop continously
*/
CATransition *animation = [CATransition animation];
[animation setRemovedOnCompletion:YES]; //better to remove the animation
[animation setBeginTime:CACurrentMediaTime()]; //not really needed
[animation setDuration:0.4];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromTop];
//you can specify any key name or keep it nil. doesn't make a difference
[self.displayLabel.layer addAnimation:animation forKey:#"changeText"];
[self.displayLabel setText:#" "];
}

Process image during CATransition animation with GPUImage

I'm trying to set the image back to default when i shake the device. the problem is that, the image is processing to default and only afterwards the rippleEffect happens.
I'm trying to do this during the animation, not before nor after.
any ideas?
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if(motion == UIEventSubtypeMotionShake){
CATransition *animation=[CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.0];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
[animation setType:#"rippleEffect"];
//[animation setFillMode:kCAFillModeRemoved];
animation.endProgress=0.99;
[(GPUImageBulgeDistortionFilter *)sepiaFilter setScale:0.0];
[sourcePicture processImage];
[animation setRemovedOnCompletion:NO];
[self.view.layer addAnimation:animation forKey:nil];
}
}

How to implement method: - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag

I have two blocks of code (described also in another topic)
- (void)AnimateImage:(NSString*)direction{
self.CurrentAnimal.image = [images objectAtIndex:image_nr];
CATransition *animation = [CATransition animation];
[animation setDuration:1.0];
[animation setType:kCATransitionPush];
if([direction isEqualToString:#"left"]){
[animation setSubtype:kCATransitionFromLeft];
}
else {
[animation setSubtype:kCATransitionFromRight];
}
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[[self.CurrentAnimal layer] addAnimation:animation forKey:nil];
}
And
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
//do what you need to do when animation ends...
}
I know that I need to "set the delegate property and implement the method" to catch animationDidStop event but I'm not able to get it working.
Question - How do I set up my .h and .m files so that I'm able to use this method to execute code when CATransition animation stops?
Set up the delegate:
CATransition *animation = [CATransition animation];
....
[animation setDelegate:self];
[animation setDuration:1.0];
[animation setType:kCATransitionPush];
You first have to add the Delegate to the CATransition object you created like that
CATransition *animation = [CATransition animation];
[animation setDelegate = self];
[animation setValue:animation.values.lastObject forKey:#"myAnimationKey"];
If you set a key for your animation, you can exactly check which animation ended. If you have just one animation, you don't need a specific key. If you set a key you can check which animation ended like that:
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if(anim == [animation.layer animationForKey:#"myAnimationKey"]){
}
}

Custom UIViewController Transition?

There are another custom UIViewController transition than the 4 natives iOS:
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
Any tips?
You could also try CATransition, for example, the code below shows a transition where a second view pushes your current view out to the right. (Assuming this code is placed in your main view controller).
UIView *appWindow = [self.view superview];
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[appWindow addSubview:yourSecondViewController.view];
[self.view removeFromSuperview];
[[appWindow layer] addAnimation:animation forKey:#"showSecondViewController"];

Resources