Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone “创建itunes商店风格”;“跳跃”;动画_Iphone_Objective C_Ios_Cocoa Touch_Core Animation - Fatal编程技术网

Iphone “创建itunes商店风格”;“跳跃”;动画

Iphone “创建itunes商店风格”;“跳跃”;动画,iphone,objective-c,ios,cocoa-touch,core-animation,Iphone,Objective C,Ios,Cocoa Touch,Core Animation,我正在为我的应用程序创建一个书签功能,我想以类似于itunes商店的方式向用户展示,当你买东西时,它会跳转到tabBar。我曾经看过一些WWDC的视频解释了这一点,但不记得怎么做了。你知道我应该从哪里开始寻找吗?你可以拍下你想要设置动画的视图的快照,然后创建一个图像层,然后使用核心动画将其设置到选项卡栏。下面是我用来做这件事的代码: - (void)animateSnapshotOfView:(UIView *)view toTab:(UINavigationController *)navCo

我正在为我的应用程序创建一个书签功能,我想以类似于itunes商店的方式向用户展示,当你买东西时,它会跳转到tabBar。我曾经看过一些WWDC的视频解释了这一点,但不记得怎么做了。你知道我应该从哪里开始寻找吗?

你可以拍下你想要设置动画的视图的快照,然后创建一个图像层,然后使用核心动画将其设置到选项卡栏。下面是我用来做这件事的代码:

- (void)animateSnapshotOfView:(UIView *)view toTab:(UINavigationController *)navController
{
    NSUInteger targetTabIndex = [self.tabBarController.viewControllers indexOfObject:navController];
    NSUInteger tabCount = [self.tabBarController.tabBar.items count];
    // AFAIK there's no API (as of iOS 4) to get the frame of a tab bar item, so guesstimate using the index and the tab bar frame.
    CGRect tabBarFrame = self.tabBarController.tabBar.frame;
    CGPoint targetPoint = CGPointMake((targetTabIndex + 0.5) * tabBarFrame.size.width / tabCount, CGRectGetMidY(tabBarFrame));
    targetPoint = [self.window convertPoint:targetPoint fromView:self.tabBarController.tabBar.superview];

    UIGraphicsBeginImageContext(view.frame.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    CGRect frame = [self.window convertRect:view.frame fromView:view.superview];
    CALayer *imageLayer = [CALayer layer];
    imageLayer.contents = (id)image.CGImage;
    imageLayer.opaque = NO;
    imageLayer.opacity = 0;
    imageLayer.frame = frame;
    [self.window.layer insertSublayer:imageLayer above:self.tabBarController.view.layer];

    CGMutablePathRef path = CGPathCreateMutable();
    CGPoint startPoint = imageLayer.position;
    CGPathMoveToPoint(path, NULL, startPoint.x, startPoint.y);
    CGPathAddCurveToPoint(path,NULL,
                          startPoint.x + 100, startPoint.y,
                          targetPoint.x, targetPoint.y - 100,
                          targetPoint.x, targetPoint.y);
    CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    positionAnimation.path = path;
    CGPathRelease(path);

    CABasicAnimation *sizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
    sizeAnimation.fromValue = [NSValue valueWithCGSize:imageLayer.frame.size];
    sizeAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(50, 50)];

    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacityAnimation.fromValue = [NSNumber numberWithFloat:0.75];
    opacityAnimation.toValue = [NSNumber numberWithFloat:0];

    CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
    animationGroup.animations = [NSArray arrayWithObjects:positionAnimation, sizeAnimation, opacityAnimation, nil];
    animationGroup.duration = 1.0;
    animationGroup.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    animationGroup.delegate = self;
    [animationGroup setValue:imageLayer forKey:@"animatedImageLayer"];

    [imageLayer addAnimation:animationGroup forKey:@"animateToTab"];
}

伟大的我只是得到了一个基本的图像,我需要反弹到tabbar,我认为这将做得很好!谢谢丹尼尔,这真的很有帮助!:)