Mar*_*ark 7 objective-c uiviewcontroller uiviewanimation ios ios7
我正在尝试进行一个非常简单的过渡:一个视图将屏幕的一半移动到左侧,而第二个("到")视图移动半个屏幕.
我有动画工作,但当我反转动画时,我看到一个闪烁."to"视图(即原始视图)在0,0的原点可见,尽管我设置了不同的帧.
我转储了视图层次结构.帧设置正确(-100 0; 320 480用于查看),但是它显示为0,0.视图的屏幕截图是否缓存在动画的某处?
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *container = [transitionContext containerView];
CGRect offsetCoverRect = CGRectMake(-100.0, 0.0, 320, 480);
CGRect detailsRect = CGRectMake(-100.0 + 320.0, 0.0, 320, 480);
CGRect detailsOutsideRect = CGRectMake(320.0, 0.0, 320, 480);
CGRect normalRect = CGRectMake(0.0, 0.0, 320, 480);
if (self.revealDetails)
{
toViewController.view.frame = detailsOutsideRect;
[container addSubview:toViewController.view];
}
else
{
[container insertSubview:toViewController.view belowSubview:fromViewController.view];
// reversing… set the frame to the original offset (shows at 0,0 for a moment)
toViewController.view.frame = offsetCoverRect;
}
[UIView animateKeyframesWithDuration:2 delay:0 options:0 animations:^{
if (self.revealDetails)
{
fromViewController.view.frame = offsetCoverRect;
toViewController.view.frame = detailsRect;
}
else
{
fromViewController.view.frame = detailsOutsideRect;
toViewController.view.frame = normalRect;
}
} completion:^(BOOL finished) { [transitionContext completeTransition:finished]; }];
}
Run Code Online (Sandbox Code Playgroud)
更新:
这似乎与...有关UIModalPresentationCustom.我需要使用它,以便在转换完成时不删除from视图.但是,它似乎假设反向转换的from视图控制器从0,0开始.
更新2:
使用以下代码非常容易重现:
UIView *snapshot = [containerView snapshotViewAfterScreenUpdates:NO];
[containerView addSubview:snapshot];
Run Code Online (Sandbox Code Playgroud)
以上将显示以屏幕为中心的视图,无论我在动画之前设置的实际帧或中心.
小智 -2
这是因为您的 animateTransition 方法是从后台调用的。以这种方式调用你的方法
dispatch_async(dispatch_get_main_queue(), ^
{
[self animateTransition]; // your method goes here
});
Run Code Online (Sandbox Code Playgroud)
你不应该在后台线程上调用任何动画或任何与 UI 相关的方法
| 归档时间: |
|
| 查看次数: |
1664 次 |
| 最近记录: |