Keyframe animation takes long time to start after UIView animateWithDuration is called - ios

I am using the following method to chain animations:
[UIView animateWithDuration:0.3 delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^(){
// Animations here
}
completion:^(BOOL finished) {
if (finished) {
// Chained animation
}
}];
These animations play whenever I present and dismiss a view controller, call it View Controller 1.
When I load a second view controller, View Controller 2, I display an interstitial loading view on top of mainWindow, where mainWindow is
UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
This interstitial loading view shows a spinner that is animated using a keyframe animation.
The problem I am running into is that if I load View Controller 1 multiple times (say 5+ times), then load View Controller 2, the spinner animation begins to take a long time to start. After entering View Controller 1 several more times, then entering View Controller 2, View Controller 2's animation takes so long to begin that the loading view is removed before the spinner ever gets a chance to start animating.
Does anyone know what might be causing this behavior? Does it have anything to do with UIView animations not being properly removed when I leave View Controller 1?

Call the method in the main_queue , this solved my problem.
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.3 delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^(){
// Animations here
}
completion:^(BOOL finished) {
if (finished) {
// Chained animation
}
}];
});

Related

When i switch View In TabBarController the ScrollView Stop Scroll,How to Solve it?

in Controller A: here the Code:
[UIView animateWithDuration:5 animations:^{
[self.awardScrollView setContentOffset:CGPointMake(self.awardScrollView.frame.size.width * 19, 0)];
} completion:^(BOOL finished) {
isFinished = YES;
}];
i set 5s to finish the animation,but i switch controller to B with TabBarController,i found the animation is stop in Controller A.How can i let the ScrollView continue Scroll Background in Controller A even i Switch to Controller B?
Core Animation won't animate a view that's not in the on-screen view hierarchy. When a view is removed from the on-screen view hierarchy, Core Animation removes all animations from the view.
You can add another animation when the view comes back on screen if you want.

How do I see the progress of a pop animation?

I have a master and detail view controller. I have a button that currently disappears after the push segue to the detail and reappears when the pop segue is called, whether it's the interactive gesture or the back button.
This looks really abrupt and I wanted to fade in the alpha on the button with the pop gesture but I don't see any delegate or datasource methods for UINavigationControllerDelegate that show the progress of the pop gesture. Are there any libraries that help with this?
This can be accomplished with a UIView animation.
The idea is to set the alpha of the button to 0 so that it is invisible and then animate it to a value of 1 to create a fade-in effect.
self.myButton.alpha = 0;
[[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.myButton.alpha = 1;
} completion:^(BOOL finished) {
// Code for completion of animation.
}];
This could be placed in the viewDidAppear: method of your view controller.

transitionFromView with UIViewAnimationOptions similar like navigating with UINavigationController

I'm using a similar approach described here for the animation from one view controller to another:
UIWindow *window = (UIWindow *)[[UIApplication sharedApplication].windows firstObject];
[UIView transitionFromView:window.rootViewController.view
toView:vc.view
duration:0.65f
options:UIViewAnimationOptionTransitionCrossDissolve // transition animation
completion:^(BOOL finished){
window.rootViewController = vc;
}];
Looking into the UIViewAnimationOptions I didn't found an option for the default animation, which occurs when doing the same with UINavigationController.
Is it possible to get the same animation behavior (moving the view left)? How?
I tried it with this animation:
[UIView animateWithDuration:0.65 animations:^{
view.transform = CGAffineTransformMakeTranslation(-view.frame.size.width, 0);
} completion:^(BOOL finished) {
// do something
}];
but while translating to the new view the background is completely black instead of bringing the other view controller in.
Now I'm doing it in a different way. I start with my navigation controller and its root view. Then I push another view controller on the stack. In viewDidAppear of this new view controller I'm removing the first view controller from the navigation stack. One downside: You can see the back button for a short time.
The animation solution I tried will need the other view controller animated in. Also I had problems with views which very not layout correctly (because of edgesForExtendedLayout).

Half Hidden view under the main view is showing in alpha segue

[sourceViewController.view addSubview:destinationController.view];
[destinationController.view setFrame:sourceViewController.view.window.frame];
[destinationController.view setTransform:CGAffineTransformMakeScale(0.5,0.5)];
[destinationController.view setAlpha:0.0];
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:^{
[destinationController.view setTransform:CGAffineTransformMakeScale(1.0,1.0)];
[destinationController.view setAlpha:1.0];
//[sourceViewController.view setAlpha:0];
}
completion:^(BOOL finished){
[destinationController.view removeFromSuperview];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
}];
My destinationController has 2 views one over the other. View #1 is the main view and totally visible and View #2 that is half visible half hidden. When I use the code above and move between segues I can see (while going from alpa 0 to 1) the hidden view completely under the main view. So the user can see what is hidden under there. (even if I make the animateWithDuration really fast). I don't know why this is happening and trying to find a creative solution. One solution I came up with is using an animation inside the ViewController
[UIView animateWithDuration:0.7 animations:^() {_image.alpha = 1;}];
and by that "slowing down" the hidden view but obviously the view is loaded in a delay and doesn't look so elegant on the visible part of the hidden view.
Thanks
You could hide the partly hidden view first, just before your animation, or set up another animation (which will run concurrently) to set the hidden view's alpha to 0. Run this animation at the same or faster rate than your main view animation.

UIView animation doesn't get called when view is reloaded

I have programmed the following animation for an UIImageView which works fine when I load the View:
-(void) viewDidAppear:(BOOL)animated{
[UIView animateWithDuration:2
delay:0
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
hat.transform = CGAffineTransformMakeRotation(0.2);
}completion:nil
];
}
Then I push a new View Controller on top of this view, but when I pop this new view controller, the animation doesn't fire... I've tried placing this animation code in viewDidload and in viewWillAppear but that didn't help... Any thoughts?
is it possible that the UIImage view is getting unloaded? If you haven't already try setting strong/retain property to your UIImageView.

Resources