简体   繁体   English

动画,就像从iPhone照片库中删除一样

[英]Animation, like when you delete from iPhone Photo Gallery

I try to implement the animation: when you enter iPhone Gallery, press the image, you see full-screen image. 我尝试实现动画:当你进入iPhone图库时,按下图像,你会看到全屏图像。 Below you can see toolbar with trash button. 下面你可以看到带有垃圾按钮的工具栏。 When you press this button, the image is being deleted with animation. 按此按钮时,图像将被动画删除。 I try to implement this, but I don't know, how to implement the transform of image, apple use. 我试着实现这个,但我不知道,如何实现图像的转换,苹果的使用。 This is the best, I could do: 这是最好的,我能做到:

[UIView transitionWithView:self.view duration:0.1 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        [self.view addSubview:scrollImageView];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
            CGRect frame = scrollImageView.frame;
            frame.size = CGSizeMake(frame.size.width * 0.75, frame.size.height * 0.75);
            frame.origin = CGPointMake((size.width - frame.size.width) / 2, (size.height - frame.size.height) / 2);
            scrollImageView.frame = frame;
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
                CGRect frame = scrollImageView.frame;
                frame.size = CGSizeMake(frame.size.width * 0.05, frame.size.height * 0.05);
                frame.origin = CGPointMake(size.width, size.height);
                scrollImageView.frame = frame;
                CGAffineTransform transform = scrollImageView.transform;
                CGAffineTransform rotatedTransform = CGAffineTransformRotate(transform, 45 * 3.14 / 180);
                scrollImageView.transform = rotatedTransform;
            } completion:^(BOOL finished) {
                [scrollImageView removeFromSuperview];
            }];
        }];
    }];

Thank you in advance. 先感谢您。

Update As I understand, I can't do this animation with Core-Animation, but may anyone can advice me the animation the most simular to iPhone Gallery animation, but without using OpenGL? 更新据我所知,我无法使用Core-Animation制作这个动画,但是任何人都可以向我推荐与iPhone Gallery动画最相似的动画,但不使用OpenGL?

You can use following example for this animation: 您可以对此动画使用以下示例:

UIView *senderView = (UIView*)sender;

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform"];
            anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
            anim.duration = 0.125;
            anim.repeatCount = 1;
            anim.autoreverses = YES;
            anim.removedOnCompletion = YES;
            anim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)];
            //[senderView.layer addAnimation:anim forKey:nil];


UIBezierPath *movePath = [UIBezierPath bezierPath];
            [movePath moveToPoint:icon.center];
            [movePath addQuadCurveToPoint:senderView.center
                             controlPoint:CGPointMake(senderView.center.x, icon.center.y)];

            CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
            moveAnim.path = movePath.CGPath;
            moveAnim.removedOnCompletion = YES;

            CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
            scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
            scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
            scaleAnim.removedOnCompletion = YES;

            CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
            opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
            opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
            opacityAnim.removedOnCompletion = YES;

            CAAnimationGroup *animGroup = [CAAnimationGroup animation];
            animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim, opacityAnim, nil];
            animGroup.duration = 0.5;
            [icon.layer addAnimation:animGroup forKey:nil];

I have modified the code, you have to perform following changes in it, set the sender view as self.view, and change the ending point of animation (which is currently senderView.center) according to your requirement 我修改了代码,你必须在其中执行以下更改,将发件人视图设置为self.view,并根据您的要求更改动画的结束点(当前为senderView.center)

I know its a bit late. 我知道它有点晚了。 But, you should check Ciechan's solution named BCGenieEffect . 但是,你应该检查Ciechan的名为BCGenieEffect的解决方案。 Can be found here . 可以在这里找到。 Its pure Core Animation and very easy to understand. 它纯粹的核心动画,非常容易理解。 I think that's what you are looking for. 我认为这就是你要找的东西。

Good luck 祝好运

At this point the exact animation you are talking about cannot be done using Core Animation or UIKit. 此时,您正在谈论的确切动画无法使用Core Animation或UIKit完成。 You would need to use OpenGL and apply the image as a texture and do your animation in there. 您需要使用OpenGL并将图像应用为纹理并在那里进行动画制作。

I think you are talking about the "suck" transition animation. 我想你在谈论“吮吸”过渡动画。

It is possible to trigger it, but it is a private transition, and Apple may reject your app if you use it. 可以触发它,但它是私有过渡,如果您使用它,Apple可能会拒绝您的应用程序。

This code should do it, using a transition code of 103: 这段代码应该使用103的转换代码:

[UIView beginAnimations:nil context:NULL]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; [UIView setAnimationDuration:1.0]; [UIView setAnimationTransition: transtionIndex forView:containerView cache:NO]; [UIView setAnimationTransition:transtionIndex forView:containerView cache:NO]; [containerView addSubview: newView]; [containerView addSubview:newView]; [oldView removeFromSuperview]; [oldView removeFromSuperview]; [UIView commitAnimations]; [UIView commitAnimations];

Or search the net for a Core Image transition called "suckEffect" 或者在网上搜索名为“suckEffect”的核心图像转换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM