Art*_*tem 10 animation ios autolayout
1)我有一个任务来呈现和解除带有自定义动画的模态UIViewController.
2)自定义动画是更改alpha并移动一个子元素
3)我创建FadeInAnimationController
和FadeOutAnimationController
类实现 UIViewControllerAnimatedTransitioning
如下:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
// obtain state from the context
CIToViewController *toViewController = (CIToViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
// obtain the container view
UIView *containerView = [transitionContext containerView];
// set the intial state
toViewController.view.alpha = 0.0f;
toViewController.elementBottomPosition.constant -= 20.0f;
[toViewController.view layoutIfNeeded];
// add the view
[containerView addSubview:toViewController.view];
// animate
[UIView animateWithDuration:[self transitionDuration:transitionContext]
animations:^{
toViewController.view.alpha = 1.0f;
toViewController.elementBottomPosition.constant += 20.0f;
[toViewController.view layoutIfNeeded];
}
completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
Run Code Online (Sandbox Code Playgroud)
4)elementBottomPosition
是NSLayoutConstraint,它适用于Present动画
5)问题:
对于Dismiss动画NSLayoutConstraint
不起作用,所以我不得不使用Frame做同样的事情并且它起作用.AutoLayout和iOS7不是很好,但由于我需要忽略这个视图,所以我不关心它的自动布局.
所以问题是为什么NSLayoutConstraint方法不起作用??? 我记录了约束animateTransition
:
NSLog(@"constraints %@", fromViewController.view.constraints);
Run Code Online (Sandbox Code Playgroud)
它们仍然存在.
小智 0
不要在动画块中设置自动布局常量。
toViewController.elementBottomPosition.constant -= 20.0f;
[self.view layoutIfNeeded];
toViewController.elementBottomPosition.constant += 20.0f;
//Animation block here ^{
[self.view layoutIfNeeded];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1516 次 |
最近记录: |