我发现我需要从其视图访问一个视图控制器。
这里是方法。
-(void)changePageView:(UIViewController*)newviewcont withtransitiontype:(int)t andtransitionspeed:(int)s
{
//Remove whatever view is currently loaded at index 0, this index is only to be used by "page" views
UIView *oldview = [self.view.subviews objectAtIndex:0];
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:s];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[newviewcont viewWillAppear:YES];
//[oldview viewWillDisappear:YES];
[oldview removeFromSuperview];
[self.view insertSubview:newviewcont.view atIndex:0];
//[oldview viewDidDisappear:YES];
[newviewcont viewDidAppear:YES];
}
基本上,我正在尝试编写一个通用的视图切换方法,由根控制器调用,以从根控制器的视图中交换子视图控制器的视图。
我传递一个子视图控制器,并且能够移除当前的子视图。但是为了做正确的视图切换动画,我需要访问当前视图的视图控制器。这种做法是错误的吗?它可行吗?