2

I recently updated my application to use the iOS 5.0 SDK. Within it, I am using Alex Fajowski's OpenFlow cover flow implementation.

I found that when I run the application on iOS 5.0, OpenFlow is making an incorrect transformation or Z repositioning when I swipe through images.

Is there something I can do to make OpenFlow work correctly on the iOS 5.0 SDK?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Oleg Danu
  • 4,149
  • 4
  • 29
  • 47

2 Answers2

7

I made an improvement over what you have here and it certainly makes it work smoothly (the way it used to be in iOS 4).

In AfOpenFlowView.m, instead of what you stated above (in -setUpInitialState):

leftTransform = CATransform3DTranslate(CATransform3DIdentity, 0, 0, SIDE_COVER_ZPOSITION / 2.0);
leftTransform = CATransform3DRotate(leftTransform, SIDE_COVER_ANGLE, 0.0f, 1.0f, 0.0f);
rightTransform = CATransform3DTranslate(CATransform3DIdentity, 0, 0, SIDE_COVER_ZPOSITION / 2.0);
rightTransform = CATransform3DRotate(rightTransform, SIDE_COVER_ANGLE, 0.0f, -1.0f, 0.0f);

Inside -layoutCover:selectedCover:animated, place the following code:

CGFloat newZPosition = SIDE_COVER_ZPOSITION / 2.0;

CABasicAnimation *zPositionAnimation = [CABasicAnimation animationWithKeyPath:@"zPosition"];
[zPositionAnimation setToValue:[NSNumber numberWithFloat:newZPosition]];
[zPositionAnimation setDuration:(animated ? .3 : 0.0)];
[zPositionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[zPositionAnimation setRemovedOnCompletion:NO];
[zPositionAnimation setFillMode:kCAFillModeForwards];

Now, instead of doing:

aCover.layer.zPosition = newZPosition;

Replace it with:

[aCover.layer addAnimation:zPositionAnimation forKey:nil];

You can conditionally enable either depending on whether it's running on iOS 4 or 5.

Best,

boliva
  • 5,604
  • 6
  • 37
  • 39
  • Yes, it worked but still lacked some 'smoothness' on the animation, which I fixed by adding what I just posted (which of course is based on what you originally commented). – boliva Oct 17 '11 at 12:51
2

Today, I finally found the solution for this issue. Apparently, in iOS 5, zPosition is not being animated anymore (too bad, cause the documentation does say so). This is why, this bug may be fixed, by including the correct transition into the CATransform3D.

Earlier:

    leftTransform = CATransform3DIdentity;
    leftTransform = CATransform3DRotate(leftTransform, SIDE_COVER_ANGLE, 0.0f, 1.0f, 0.0f);
    rightTransform = CATransform3DIdentity;
    rightTransform = CATransform3DRotate(rightTransform, SIDE_COVER_ANGLE, 0.0f, -1.0f, 0.0f);

Now it looks like this:

    leftTransform = CATransform3DTranslate(CATransform3DIdentity, 0, 0, SIDE_COVER_ZPOSITION);
    leftTransform = CATransform3DRotate(leftTransform, SIDE_COVER_ANGLE, 0.0f, 1.0f, 0.0f);
    rightTransform = CATransform3DTranslate(CATransform3DIdentity, 0, 0, SIDE_COVER_ZPOSITION);
    rightTransform = CATransform3DRotate(rightTransform, SIDE_COVER_ANGLE, 0.0f, -1.0f, 0.0f);

Hope it helps you guys, as it did help me.

Oleg Danu
  • 4,149
  • 4
  • 29
  • 47
  • Nice, thanks! You should definitely submit a fix over github and close the issue (https://github.com/thefaj/OpenFlow/issues/21), I think it was yourself who posted it? – boliva Oct 16 '11 at 22:33
  • Ok, this definitely provides an improvement but the animation still doesn't go as smooth as it used to… – boliva Oct 16 '11 at 23:13