xCode纸张入职效果

时间:2016-10-14 09:35:02

标签: objective-c iphone xcode uiscrollview uipageviewcontroller

我们如何实施Paper Onboarding效果。我有一个containerview和3viewconroller。我们可以在下面实现相同的东西吗?

JDK-8040892

1 个答案:

答案 0 :(得分:1)

我认为你必须阅读这个问题。

https://www.objc.io/issues/12-animations/custom-container-view-controller-transitions/

首先了解前两个阶段。

然后从github下载Stage 3:Shrink-Wrapping代码。根据该代码替换" PrivateAnimatedTransition"最后用以下代码实现。

@implementation PrivateAnimatedTransition

static CGFloat const kChildViewPadding = 16;
static CGFloat const kDamping = 0.75;
static CGFloat const kInitialSpringVelocity = 0.5;

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
    return 0.3;
}

/// Slide views horizontally, with a bit of space between, while fading out and in.
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {

    UIView *containerView = [transitionContext containerView];

    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    //UIButton *button = fromViewController.button;

    [containerView addSubview:toViewController.view];

    CGRect buttonFrame = CGRectMake(300, 450, 10, 10);

    UIBezierPath *circleMaskPathInitial = [UIBezierPath bezierPathWithOvalInRect:buttonFrame];
    CGPoint extremePoint = CGPointMake(305, 455);
    CGFloat radius = sqrt((extremePoint.x * extremePoint.x) + (extremePoint.y * extremePoint.y));
    UIBezierPath *circleMaskPathFinal = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(buttonFrame, -radius, -radius)];

    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.path = circleMaskPathFinal.CGPath;
    toViewController.view.layer.mask = maskLayer;

    CABasicAnimation *maskLayerAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
    maskLayerAnimation.fromValue = (__bridge id _Nullable)(circleMaskPathInitial.CGPath);
    maskLayerAnimation.toValue = (__bridge id _Nullable)(circleMaskPathFinal.CGPath);
    maskLayerAnimation.duration = [self transitionDuration:transitionContext];
    [maskLayer addAnimation:maskLayerAnimation forKey:@"path"];

    [self performSelector:@selector(finishTransition:) withObject:transitionContext afterDelay:[self transitionDuration:transitionContext]];
}

- (void)finishTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
    [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
    [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey].view.layer.mask = nil;
}

和&#34; BINGO&#34;你做完了只需将buttonFrame替换为实际选择的索引按钮的框架即可。随意询问任何查询