animateKeyframesWithDuration make screen Not responding after animation - ios

I use animateKeyframesWithDuration to simple animate my view:
[UIView animateKeyframesWithDuration:1.0 delay:0.0 options:0 animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{
containerView.center = CGPointMake(containerView.center.x, 150);
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{
containerView.center = oldCenter;
}];
}completion:^(BOOL finished) {
}];
After the animation finished (completion block called with finished = YES), the UIViewController isn't responsive, e.g. I can't press any UIButton on top the UIViewController.
Why that?

I added this line in the completion block:
[transitionContext completeTransition:NO];
That fix my problem.

Related

UIPanGestureRecognizer conflict with constraints animation

I have an animation of a contentView of a cell wish have UIPanGestureRecognizer.
the UIPanGestureRecognizer works fine and detect touches but while the animation is happening it doesn't detect touches until it finish the animation.
is there a workaround for this.
this is the animation block
[self.myContentView layoutIfNeeded];
self.contentViewLeftConstraint.constant = -50;
self.contentViewRightConstraint.constant = 50;
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
[self.myContentView layoutIfNeeded];
} completion:completion];
Thanks.
If you want to allow user interaction during the animation, you must set the option to allow it:
UIViewAnimationOptions options = UIViewAnimationOptionCurveEaseOut |
UIViewAnimationOptionAllowUserInteraction;
[UIView animateWithDuration:duration delay:0 options:options animations:^{
[self.myContentView layoutIfNeeded];
} completion:completion];

Different animation duration for subviews of an UIView

I have the following code
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
mainPage.frame=CGRectMake(0, -[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.width);
} completion:nil];
Is there any way to control the animation duration of the subviews of mainPage.
You can use UIView:animateKeyframesWithDuration then use UIView:addKeyframeWithRelativeStartTime to set its start time and duration
[UIView animateKeyframesWithDuration:2 delay:0 options:0 animations:^{
[UIView addKeyframeWithRelativeStartTime:0.32 relativeDuration:0.68 animations:^{
view.frame = frame;
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:1 animations:^{
subview.frame = frame2;
}];
} completion:^(BOOL finished) {
}];
If you want the subviews to animate with a different duration then you'll need to animate each of them separately. You can loop through the mainPage.subviews array and issue an animateWithDuration:delay:options:animations:completion: call to each subview in turn, each with a different duration.

UIView Animation Move

I have managed to make the "view" move once. I need for it to stay 1 second in same place and then move back again to initial place. How would I add the rest of the code for this? (This won't be a loop, only done once)
[UIView animateWithDuration:0.8 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[infoView setCenter:CGPointMake(160,30)];
} completion:nil];
Use the completion block to do another animation:
[UIView animateWithDuration:0.8 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[infoView setCenter:CGPointMake(160,30)];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.8 delay:1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[infoView setCenter:CGPointMake(orignalX, originalY)];
} completion:nil];
}];

Lag between 2 animations

I am trying to animate one of my image form bottom to Top of my screen , for that i am implementing an animation that the current width and height of image will become half during the transition stage and will take its original size once animation completes.
The issue is once the 1st animation is done it hold's for a while and then starts another animation , i want a smooth animation .
Here is the code :
[UIView animateWithDuration:1.0
delay:0.5
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[_myImageView setFrame:CGRectMake(20.0, 220.0, currentframe.size.width/2, currentframe.size.height/2)];
} completion:^(BOOL finished)
{
if (finished)
{
[UIView animateWithDuration:1.0
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[_myImageView setFrame:CGRectMake(20.0, 20.0, currentframe.size.width, currentframe.size.height)];
} completion:^(BOOL finished) {
if (finished) {
NSLog(#"2 nd log ");
}
}];
NSLog(#"animation fisnished !!");
}
}];
What should be done ?
try this:
[UIView animateWithDuration:1.0
delay:0
options:UIViewAnimationOptionCurveLinear// use CurveLinear option
animations:^{
} completion:^(BOOL finished) {
}];

Apply some easing into UIImageView animation

I am using the following to make a UIImageView slide a little bit forward, and then slide back farther for a parallax scrolling effect.
Code:
[UIView animateWithDuration:0.2f animations:^{
spendrBckGrnd.frame = CGRectMake(spendrBckGrnd.frame.origin.x + 20, 0, spendrBckGrnd.frame.size.width, spendrBckGrnd.frame.size.height);
}];
[UIView animateWithDuration:0.4f animations:^{
spendrBckGrnd.frame = CGRectMake(spendrBckGrnd.frame.origin.x - 80, 0, spendrBckGrnd.frame.size.width, spendrBckGrnd.frame.size.height);
}];
I am wondering how I might go about applying some easing into the animation, right now if just abruptly slides back and forth quickly. I would like to ease into and out of the sliding animations.
You need to do the second animation block after the first one completes.
[UIView animateWithDuration:0.2f animations:^{
spendrBckGrnd.frame = CGRectMake(spendrBckGrnd.frame.origin.x + 20, 0, spendrBckGrnd.frame.size.width, spendrBckGrnd.frame.size.height);
} completion:^{
[UIView animateWithDuration:0.2f animations:^(BOOL finished){
spendrBckGrnd.frame = CGRectMake(spendrBckGrnd.frame.origin.x - 80, 0, spendrBckGrnd.frame.size.width, spendrBckGrnd.frame.size.height);
}];
}];
This will do the trick:
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^(void){
//do your animations
} completion:^(BOOL finished){
}];
Check out this tutorial on UIView animation
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_uiview-animations/
UIView has a method
// [UIView animateWithDuration:(NSTimeInterval) delay:(NSTimeInterval) options:(UIViewAnimationOptions)animations:^(void)animations completion:^(BOOL finished)completion];
typedef enum {
UIViewAnimationCurveEaseInOut, // slow at beginning and end
UIViewAnimationCurveEaseIn, // slow at beginning
UIViewAnimationCurveEaseOut, // slow at end
UIViewAnimationCurveLinear
}
[UIView animateWithDuration:0.6f
delay:0.1f
options:UIViewAnimationCurveEaseInOut
animations:^{
[starView setCenter:CGPointMake(0, 0)];
[starView setAlpha:0.0f];
}
completion:^(BOOL finished){
[starView removeFromSuperview];
points++;
}
];
Also check out this control on github that creates a parallax effect using a custom container view, much like the top view of Path's timeline.
https://github.com/modocache/MDCParallaxView

Resources