3

I have the following code to animation some view in my app:

void (^animate)() = ^() {
    CGRect leftFrame = centerFrame;
    leftFrame.origin.x -= centerFrame.size.width;
    newViewController.view.frame = centerFrame;
    oldViewController.view.frame = leftFrame;
};

if (animated) {
    [UIView animateWithDuration:0.3f
                          delay:0.0f
                        options:nil
                     animations:animate
                     completion:^(BOOL finished){}];
} else {
    animate();
}

This animates correctly on iOS 6, however on iOS 7 there is no animation. Oddly the code inside the block does get called and the view does update, just without the animation duration taken into account.

Is there a reason why this block isn't getting called?

runmad
  • 14,846
  • 9
  • 99
  • 140
  • It's working for me on both the device and simulator – what does your animate block look like? – Ash Furrow Sep 18 '13 at 19:29
  • This is so weird. About 1/3 of the time I run the app it works. The rest of the time it does not perform the block with animation. – runmad Sep 18 '13 at 20:02
  • @AshFurrow I've updated the code example. It's definitely not just this block, several places it doesn't perform the animations from blocks that have been defined. And it's consistent throughout the app: either it does animate anything defined in blocks or it does not. – runmad Sep 18 '13 at 20:05
  • I'm making a wild guess in the dark, but are both view controllers part of the view hierarchy at the time you apply the animations? Is there any variation in whether they're part of the view hierarchy? – Tommy Sep 18 '13 at 20:50
  • @Tommy Yes, both are part of the view hierarchy as they're the one's being animated. – runmad Sep 19 '13 at 14:08
  • Same issue here. My log inside is showing - but no animation happens. – malaki1974 Sep 19 '13 at 16:57
  • And what is the original state of those two views, is it possible that one view is on top of the other, and hide the animation underneath) – Kyle Fang Sep 21 '13 at 18:17
  • Hi @runmad, it is happening the same thing to my app. It happens with ALL the animations of the app (executed when showing controller, after pressing a button, etc, that is, in every kind of situation), but it happens only sometimes, and after playing a while with the app, animations then stop animating, and just place the views in the final state. Soooooo weird. – Monitus Sep 27 '13 at 12:08
  • @Monitus Yeah, I can't quite figure it out. Doesn't seem to be an issue with apps that are built from scratch in Xcode 5/iOS 7. – runmad Sep 27 '13 at 16:27

6 Answers6

2

I had the same issue: an animation block that works like a charm in iOS6 is executed without the animation in iOS7.

Not sure if this might help you but I moved the animation trigger to viewDidAppear: and now its being animated.

So for you this might look like this:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    animate();
    // do your other stuff here...
}
Richard R
  • 873
  • 6
  • 20
  • Worked for me. My code was previously in viewDidLoad, in a UIViewController being pushed to the screen. – user339946 Sep 23 '13 at 04:50
  • But I am not doing the animations in `viewDidLoad:` it's a parent view controller that handles the animations for the child view controller's views. – runmad Sep 23 '13 at 14:10
2

Your animation may be colliding with another competing animation block, perhaps one called by UIKit during a transition. Instead of passing nil to the animation options, use:

UIViewAnimationOptionOverrideInheritedOptions | UIViewAnimationOptionBeginFromCurrentState

and see if this helps.

jaredsinclair
  • 12,687
  • 5
  • 35
  • 56
2

I had exactly the same regression between iOS6 and iOS7.

In my case, it was due to the fact that animateWithDuration: was called before the UIView it animates appeared on screen.

In iOS7 it appears that you shouldn't call animateWithDuration: before -(void)viewDidAppear:(BOOL)animated is called on the controlling UIViewController.

Arkku
  • 41,011
  • 10
  • 62
  • 84
1

I was having the same issue. What it turned out for me is I needed to reference a different part of the UITableViewCell I was animating than I did with iOS 6. It might be a similar issue for you.

Landon Alder
  • 316
  • 3
  • 8
1

It is probably autolayout in iOS 7 which is giving you troubles. I just had the same problem. Instead of animating the frame, you need to animate the constraints.

See Are NSLayoutConstraints animatable? for how to do it.

Community
  • 1
  • 1
Jan Sindberg
  • 479
  • 6
  • 9
0

try using :

[UIView setAnimationsEnabled:YES];

topher
  • 1