当触摸基于 TabBarController 的应用程序中的视图时,如何调整大小到全屏?
以下是我的一些视图控制器:tabBarController、navigationBarController、viewController 和 imageView。
层次结构是:tabBarController是根控制器,它包括navigationBarController。 viewController(包括imageView)由navigationBarController推入。
所以问题是,当我触摸 imageView 时,如何将其大小调整为全屏并具有流畅的动画。请注意,我不想隐藏 NavigationBar &标签栏。
我通过setFrame
尝试过,但是,它被navigationBarController和tabBarController覆盖。
我尝试了 presentModalViewController:
但它失去了连续性。
我还尝试将 rootViewController
重置为 viewController,但结果导致动画损坏。 :(
感谢您的任何建议!
测试代码
UIViewController * viewController = [[UIViewController alloc] init];
[viewController.view setFrame:CGRectMake(0.0f, 0.0, 320.0f, 480.0f)];
[viewController.view setBackgroundColor:[UIColor redColor]];
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[imageView setBackgroundColor:[UIColor yellowColor]];
[imageView setUserInteractionEnabled:YES];
[viewController.view addSubview:imageView];
[imageView release];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController release];
UIViewController * anotherTabViewController = [[UIViewController alloc] init];
[anotherTabViewController.view setFrame:CGRectMake(0.0f, 0.0, 320.0f, 480.0f)];
[anotherTabViewController.view setBackgroundColor:[UIColor blueColor]];
UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, anotherTabViewController, nil];
[navigationController release];
[anotherTabViewController release];
[self.window setRootViewController:tabBarController];
这里我写了一个简单的代码进行测试。现在不关心触摸动作。我想知道如何将 imageView 设置为完全全屏(宽度:320,高度:480)。但它被导航栏和标签栏剪切了。我知道框架是相对于它的超级视图的。如何处理这个问题?
Here're some view controller I have: tabBarController, navigationBarController, viewController, and imageView.
The hierarchy is that: tabBarController is the root controller, it includes navigationBarController. And the viewController(which is include the imageView) is pushed in by navigationBarController.
So the question is, when I touched the imageView, how to resize it to fullscreen with smooth animation. Note, I don't want to hide NavigationBar & TabBar.
I tried it by setFrame
, however, it is covered by navigationBarController and tabBarController.
I tried presentModalViewController:
but it lose continuity.
I also tried to reset rootViewController
to viewController, but the resulted with a broken animation. :(
Thanks for any suggestion!
Test code
UIViewController * viewController = [[UIViewController alloc] init];
[viewController.view setFrame:CGRectMake(0.0f, 0.0, 320.0f, 480.0f)];
[viewController.view setBackgroundColor:[UIColor redColor]];
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[imageView setBackgroundColor:[UIColor yellowColor]];
[imageView setUserInteractionEnabled:YES];
[viewController.view addSubview:imageView];
[imageView release];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController release];
UIViewController * anotherTabViewController = [[UIViewController alloc] init];
[anotherTabViewController.view setFrame:CGRectMake(0.0f, 0.0, 320.0f, 480.0f)];
[anotherTabViewController.view setBackgroundColor:[UIColor blueColor]];
UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, anotherTabViewController, nil];
[navigationController release];
[anotherTabViewController release];
[self.window setRootViewController:tabBarController];
Here I write a simple code for testing. Now don't care about the touch action. I wonder how to set the imageView to totally fullscreen(width:320, height:480). But it's clipped by navigation bar and tab bar. I know the frame is relative to its super view. How to deal with this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您需要将其大小调整为全屏时,尝试将 img 添加到您的窗口中:
请注意,当您添加 tabBar 或 navigationBar 时,您的 self.view 的框架会自动调整大小,并且在 -(void)viewDidLoad 中它不会调整大小 jet!
try to add img to you window, when you need to resize it to full screen:
Note, that your self.view's frame automatically resized when you adding tabBar or navigationBar, and in -(void)viewDidLoad it is NOT resized jet!