开发者

Animating subviews to spin image to full screen

开发者 https://www.devze.com 2023-03-25 15:11 出处:网络
I have开发者_StackOverflow社区 an UIImageView (100x100px) and when a user taps on the image I want to do an animation which brings the image to full screen.

I have开发者_StackOverflow社区 an UIImageView (100x100px) and when a user taps on the image I want to do an animation which brings the image to full screen.

The animation is a combination of changing the frame to full screen and a CABasicAnimation which spins the image.

I have set this up like this:

[self.view bringSubviewToFront:imageView];

CGRect originalFrame = CGRectMake(20.0, 20.0, 100.0, 100.0);
CGRect fullFrame = CGRectMake(0.0, 0.0, 320.0, 320.0);

CGRect newFrame = (isImageFullScreen ? originalFrame : fullFrame);

CABasicAnimation* spinAnimation = [CABasicAnimation
                                   animationWithKeyPath:@"transform.rotation.y"];
spinAnimation.duration = 0.5;
spinAnimation.toValue = [NSNumber numberWithFloat:2*M_PI];

[imageView.layer addAnimation:spinAnimation forKey:@"spinAnimation"];


[UIView animateWithDuration:0.6
                      delay:0.25 
                    options:UIViewAnimationOptionTransitionNone
                 animations:^{
                                imageView.frame = newFrame;
                                button.frame = newFrame;
                             } 
                 completion:nil];

The problem is with the spin animation. In my view there are some other subviews that stay on top when the image spins.

How can I make this work so the image animates on top of my other subviews?


Solution found.

Added: imageView.layer.zPosition = imageView.layer.bounds.size.width;

0

精彩评论

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