这可能是一个显而易见的问题,但我无法找出解决这个问题的正确方法。我有一个自定义的 segue 类,它的工作原理是它成功地转换到目标控制器。在目标控制器中,我需要获取一些子视图的位置并将它们保存以备后用。我正在 ViewDidAppear 中执行此操作。此代码在使用标准 segue 时有效,但在使用我的自定义 segue 时位置解析为 {0, 0}。但是,我可以对子视图做其他事情,比如画一个边框。
目标视图的代码:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
for (UIView * view in self.videos) {
[self.origCenter setObject:[NSValue valueWithCGPoint:[view.superview convertPoint:view.center toView:view.superview]]
forKey:[NSValue valueWithNonretainedObject:view]];
view.layer.borderColor = [UIColor redColor].CGColor;
view.layer.borderWidth = 3.0f;
}
}
自定义segue的代码:
-(void)perform {
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationController = (UIViewController*)[self destinationViewController];
[sourceViewController.view addSubview:destinationController.view];
CATransition* transition = [CATransition animation];
transition.duration = .25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[sourceViewController.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[[self sourceViewController] presentModalViewController:[self destinationViewController] animated:NO];
}