Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation of CGAffineTransform in iOS8 looks different than in iOS7

I'm trying to find a reason why animation of UIView transform property looks different in iOS 8 than iOS 6/7.

For a simple example, prior to iOS 8:

myView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, 1.57);
[UIView animateWithDuration:5 animations:^{
    myView.transform = CGAffineTransformTranslate(plane.transform, 100, 0);
}];

gives expected result, "myView" is rotated 90 degrees and moves down, but in iOS8 when translation is animated it starts at a point that I couldn't find explanation for (which breaks the animation).

Does anyone know the explanation for it? Thanks in advance!

like image 250
maniacus Avatar asked Aug 13 '14 12:08

maniacus


3 Answers

CGAffineTransformIdentity behaves differently on ios7 and ios8. This has to do with auto-layout and size classes. The solution is to remove constraints that conflict with the animation on ios7.

// solve the constraint-animation problem
if(NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) {
    // iOS7 remove constraints that conflict with animation
    if (self.centerYAlignment != nil) {
        self.view.removeConstraint(self.centerYAlignment) //is an IBOutlet 
    }
} else {
    // iOS8 constraint animations are fine
}
like image 159
Pbk Avatar answered Nov 15 '22 18:11

Pbk


I think the reason is just iOS8 bug, but I use CAAnimation instead, and it works as expected on iOS8.

like image 41
AndrewK Avatar answered Nov 15 '22 19:11

AndrewK


I had problems with jerky rotation transform in iOS7 as well. Solved this by nesting my rotated view inside a container and centering the rotated view inside.

like image 2
ShayDavidson Avatar answered Nov 15 '22 18:11

ShayDavidson