所以我正在尝试重新创建这样的东西:
目前我正试图在这种情况下为单个元素设置动画,右边的框是UIImageView
。
目前我在使用animateTransition函数时出现问题,该函数似乎错误地移动了UIImageView
。首先,它始终在左上角开始,其次不会移动到正确的位置。 (似乎问题在于X的位置)。
这是我的代码(非常粗糙):
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
DetailViewController *toViewController = (DetailViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
TableViewController* fromViewController = (TableViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UITableViewCell *cell = [fromViewController.tableView cellForRowAtIndexPath:[fromViewController.tableView indexPathForSelectedRow]];
UIImageView *cellImage = [cell viewWithTag:1];
[[transitionContext containerView] addSubview:cellImage];
[[transitionContext containerView] addSubview:toViewController.view];
[[transitionContext containerView] bringSubviewToFront:cellImage];
NSLog(@"FromFrame: %@, toFrame: %@", NSStringFromCGRect(cellImage.frame), NSStringFromCGRect(toViewController.headerImage.frame));
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
CGPoint finalCenterPoint = toViewController.headerImage.center;
cellImage.center = finalCenterPoint;
toViewController.view.alpha = 1;
} completion:^(BOOL finished) {
fromViewController.view.transform = CGAffineTransformIdentity;
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}
会喜欢一些反馈。此外,我设法找到使用快照的解决方案但是我不确定它们是最有效的方法吗?
另一个考虑因素是如何处理NON共享元素?