- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码:
导航器.m
- (void)newPushPage:(UIViewController *)controller
{
[self pushViewController:controller animated:YES];
}
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC
{
if (operation == UINavigationControllerOperationPush || operation == UINavigationControllerOperationPop)
{
self.animator = [Animator new];
return self.animator;
}
return nil;
}
动画师.m
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return 0.5;
}
- (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]];
}];
}
在 pushPage 和屏幕出现后,出现了一个问题:隐藏在代码中的所有元素都可见,我可以看到元素如何消失已经看到屏幕。看起来不雅观。有办法吗?
最佳答案
在 animateTransition (id)transitionContext 协议(protocol)中,push 和 pop 转换必须按如下方式单独处理。
//1.fromVC 的设置..
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
CGRect sourceRect = [transitionContext initialFrameForViewController:fromVC];
CGRect finalFrameForVC = [transitionContext finalFrameForViewController:toVC];
//2.插入toVC View 。
if(pushCondition) {
UIView *container = [transitionContext containerView];
[container insertSubview:toVC.view aboveSubview:fromVC.view];
toVC.view.alpha = 0.5;
toVC.view =
} else if (popCondition ){
UIView *container = [transitionContext containerView];
toVC.view.frame = finalFrameForVC;
toVC.view.alpha = 0.5;
[container addSubview:toVC.view];
[container sendSubviewToBack:toVC.view];
UIView *snapShoot = [fromVC.view snapshotViewAfterScreenUpdates:false];
}
//3.执行动画
[UIView animateWithDuration:1.0
delay:0.0
usingSpringWithDamping:1.0
initialSpringVelocity:6.0
options:UIViewAnimationOptionCurveLinear
animations:^{
//Setup the final parameters of views for push
toVC.view // update final view frame
toVC.view.alpha = 1.0;
//Setup the final parameters of views for pop
snapShoot.frame =
} completion:^(BOOL finished) {
//When the animation is completed call completeTransition with final push value
[snapShoot removeFromSuperview];
//When the animation is completed call completeTransition with final push value
toVC.view.alpha= 1.0;
[transitionContext completeTransition:YES];
}];
在 amimator 中创建枚举/标志属性并将其设置在导航 Controller 委托(delegate)中。
if (operation == UINavigationControllerOperationPush)
{
self.animator = [Animator new];
self.animator.pushPopAnimation = UINavigationControllerOperationPush;
return self.animator;
}
请参阅上面代码中的 snapshotViewAfterScreenUpdates:(BOOL)afterUpdates 方法的苹果文档。
关于ios - UIViewControllerContextTransitioning 和 UINavigationControllerDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36790726/
我已经使用 MyNavigationControllerAnimations 为我的导航 Controller 实现了自定义动画,并且我需要根据用户事件更改动画。 因此MyNavigationCont
UIViewControllerContextTransitioning的这个方法什么时候可以返回nil? viewController(forKey key: UITransitionContext
我的代码: 导航器.m - (void)newPushPage:(UIViewController *)controller { [self pushViewController:contro
我正在创建自定义导航 Controller 。事实上,我想要一个带有“内容 View ”的 UINavigationController,它不一定是全屏,但可以是任何 View 。 由于我还想使用自定
我想实现自定义 ViewController 转换。那里有很多解决方案。其中大多数都基于 UIViewControllerContextTransitioning 或 UIViewController
我在 View Controller 的中间有一个正方形。我想为它设置动画并将其移动到新的 View Controller 。但是,当我这样做时,它会重置为 (0,0)。有什么建议吗? -(void)
我遇到了一个问题,我在下面进行了描述。 我正在使用 UIViewControllerContextTransitioning 进行自定义转换。 我有 2 个 View Controller ,第一个
我正在使用带有“全屏”演示文稿的 segue 以模态方式展示 VC,这意味着在转换之后,两个 View 都不会从层次结构中删除。我们将 Controller 称为 fromViewController
我是一名优秀的程序员,十分优秀!