gpt4 book ai didi

ios - 如何使选项卡栏自定义动画仅发生在某个 View Controller 上?

转载 作者:行者123 更新时间:2023-11-30 13:42:45 25 4
gpt4 key购买 nike

我有一个在选择选项卡时的自定义动画,但我希望该动画仅在单击某个选项卡时出现。我猜测这与 toView 的实例化有关。错误http://puu.sh/n5VuA/c3e886957e.png

class TransitioningObject: NSObject, UIViewControllerAnimatedTransitioning {

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
// Get the "from"nd "to" views
let fromView : UIView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
let toView : UIView = transitionContext.viewForKey(UITransitionContextToViewKey)!


transitionContext.containerView()!.addSubview(fromView)
transitionContext.containerView()!.addSubview(toView)

//The "to" view with start "off screen" and slide left pushing the "from" view "off screen"
toView.frame = CGRectMake(toView.frame.width, 0, toView.frame.width, toView.frame.height)
let fromNewFrame = CGRectMake(-1 * fromView.frame.width, 0, fromView.frame.width, fromView.frame.height)

UIView.animateWithDuration(transitionDuration(transitionContext), animations: { () -> Void in
toView.frame = CGRectMake(0, 0, 320, 560)
fromView.frame = fromNewFrame
}) { (Bool) -> Void in

transitionContext.completeTransition(true)
}

}

func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return 0.35
}
}

这是 View Controller 代码

override func viewDidLoad() {
super.viewDidLoad()

let animatedTransitioningObject = TransitioningObject()
animatedTransitioningObject.animateTransition(UIViewControllerContextTransitionin) //I get an error here
// Do any additional setup after loading the view.
}

最佳答案

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
[[transitionContext containerView] addSubview:toViewController.view];
toViewController.view.alpha = 0;

[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
fromViewController.view.transform = CGAffineTransformMakeScale(0.1, 0.1);
toViewController.view.alpha = 1;
} completion:^(BOOL finished) {
fromViewController.view.transform = CGAffineTransformIdentity;
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];

}];

}

你的动画函数应该是什么样子。

此外,如果您想要一个为您执行此操作的 Pod,我建议您查看此 Pod

https://github.com/Ramotion/animated-tab-bar Animated Tab bar pod

关于ios - 如何使选项卡栏自定义动画仅发生在某个 View Controller 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35374768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com