gpt4 book ai didi

ios - Cocoa 编程的概念或技术问题

转载 作者:行者123 更新时间:2023-12-03 16:48:44 25 4
gpt4 key购买 nike

我发现自己需要从 View Controller 的 View 访问它。

方法如下

-(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];

}

基本上,我正在尝试编写一个由根 Controller 调用的通用 View 切换方法,以从根 Controller View 中交换 subview Controller View 。

我传入一个 subview Controller ,并且能够删除当前的 subview 。但为了执行正确的 View 切换动画,我需要访问当前 View View Controller 。这是错误的做法吗?可以这样做吗?

最佳答案

我向根 Controller 添加了一个成员,该成员保留当前 subview Controller (currentController) 并在 Controller 交换完成时引用它

-(void)changePageView:(UIViewController*)newviewcont withtransitiontype:(int)t andtransitionspeed:(int)s
{


[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:s];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[newviewcont viewWillAppear:YES];
[self.currentController viewWillDisappear:YES];
[self.currentController.view removeFromSuperview];
[self.view insertSubview:newviewcont.view atIndex:0];
[self.currentController viewDidDisappear:YES];
[newviewcont viewDidAppear:YES];
[UIView commitAnimations];


self.currentController = newviewcont;

}

关于ios - Cocoa 编程的概念或技术问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/600866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com