开发者

UILayer custom 'compact' animation, looking for anchor help

I'm trying to create an animation for a layer where the bottom of the layer flips up. Think of a view hinged on the top, then the botton a开发者_Python百科nimates out and up. Like the cover of a compact. What I want is like the standard flip animation but to only see one side of it. I'm just having trouble structuring the animation.

The problem is I got the animation right accept I can't seem to create the 'hinge' part. That is, the hinge is in the center instead of the top. What am I missing?

Here's the code:

   [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                CATransform3D frontTransform = CATransform3DIdentity;
                frontTransform.m34 = 1.0 / -850.0; 
                CATransform3D rotation = CATransform3DRotate(frontTransform, M_PI/2, 1.0, 0.0, 0.0);
                frontTransform = CATransform3DTranslate(frontTransform, 0.0, 0.0, menuView.bounds.size.height);
                frontTransform = CATransform3DConcat(rotation, frontTransform);
                menuView.layer.transform = frontTransform;

            }completion:^(BOOL finished){
                if (finished) {
                    [self.window sendSubviewToBack:menuView];
                    CATransform3D backTransform = CATransform3DIdentity;
                    backTransform.m34 = 0.0f; //Must be first before setting any other properties.
                    backTransform = CATransform3DRotate(backTransform, M_PI, 0.0, 0.0, 0.0);
                    backTransform = CATransform3DTranslate(backTransform, 0.0, 0.0, 0.0);
                    menuView.layer.transform = backTransform;
                }
            }];

I'm trying to animate the layer as described above, then send the layer's view behind all other views on completion, and return the layer to it's original state so I can bring it to the front later.

Thanks for the help!


Have you tried to set CALayer's anchor point to the top? Here at top middle point:

menuView.layer.anchorPoint = CGPointMake(CGRectGetWidth(menuView.bounds)/2, 0.0);


Fixed the problem. I had to set both the layer's anchor point and position properties.

menuView.layer.position = CGPointMake(menuView.frame.size.width/2, 0.0);
menuView.layer.anchorPoint = CGPointMake(0.5, 0.0);


[UIView animateWithDuration:0.8 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
                menuView.layer.magnificationFilter = kCAFilterNearest;
                menuView.layer.edgeAntialiasingMask = kCALayerBottomEdge;

                CATransform3D backTransform = CATransform3DIdentity;
                backTransform.m34 = 0.0f; 
                backTransform.m43 = 0.0f;
                backTransform = CATransform3DTranslate(backTransform, 0.0, 0.0, 0.0);
                backTransform = CATransform3DRotate(backTransform, M_PI/2, 0.0, 0.0, 0.0);
                menuView.layer.transform = backTransform;                   

            }completion:^(BOOL finished){
                if (finished) {
                    NSLog(@"Position - Show Second: %@", NSStringFromCGPoint(menuView.layer.position));
                    NSLog(@"AnchorP - Show Second: %@", NSStringFromCGPoint(menuView.layer.anchorPoint));
                }
            }];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜