CATransition not animating from method inside UIView subclass - iphone

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

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.

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

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.

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

PageTurn animation in 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.