#objective-c #iphone #xcode #uiscrollview #uipageviewcontroller
#цель-c #iPhone #xcode #uiscrollview #uipageviewcontroller
Вопрос:
Как мы можем реализовать эффект загрузки бумаги. У меня есть один containerview и 3viewconroller внутри этого. можем ли мы реализовать то же самое, что показано ниже?
Ответ №1:
Я думаю, вам нужно прочитать этот выпуск.
https://www.objc.io/issues/12-animations/custom-container-view-controller-transitions/
Сначала разберитесь с первыми двумя этапами.
Затем загрузите этап 3: код термоусадочной упаковки с github. В соответствии с этим кодом, наконец, замените реализацию «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;
}
и «БИНГО» вы сделали. Просто замените buttonFrame на фактический выбранный фрейм индексной кнопки. Не стесняйтесь задавать любые вопросы
Комментарии:
1. У меня есть код на GitHub, который выполняет аналогичную работу. Вот ссылка: github.com/karanthakakr04/Walkthrough-Demo.git Я надеюсь, что это удовлетворит ваши потребности. Также есть это справочное руководство, если оно кому-то нужно: youtu.be/tNCsQe5vfRk