当触摸基于 TabBarController 的应用程序中的视图时,如何调整大小到全屏?

发布于 2024-12-18 10:42:49 字数 2065 浏览 3 评论 0原文

以下是我的一些视图控制器:tabBarControllernavigationBarControllerviewControllerimageView
层次结构是:tabBarController是根控制器,它包括navigationBarControllerviewController(包括imageView)由navigationBarController推入。

所以问题是,当我触摸 imageView 时,如何将其大小调整为全屏并具有流畅的动画。请注意,我不想隐藏 NavigationBar &标签栏。
我通过setFrame尝试过,但是,它被navigationBarControllertabBarController覆盖。
我尝试了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玻璃人 2024-12-25 10:42:49

当您需要将其大小调整为全屏时,尝试将 img 添加到您的窗口中:

    UIImageView *img; //create new image
    img = yourImageView;
    [img setOrigin:CGPointMake(yourImageView.frame.origin.x, yourImageView.frame.origin.y+90)]; 
//window size is bigger, so to set an image frame visionary at same place, you need to set origin point lower
    MOEAppDelegate *sharedAppDelegate = (MOEAppDelegate *)[[UIApplication sharedApplication] delegate];
    [sharedAppDelegate.window addSubview:img];
    [UIView animateWithDuration:1 
                     animations:^{
                         [img setFrame:CGRectMake(0, 
                                                  0, 
                                                  320, 
                                                  480)];
                     }];

请注意,当您添加 tabBar 或 navigationBar 时,您的 self.view 的框架会自动调整大小,并且在 -(void)viewDidLoad 中它不会调整大小 jet!

try to add img to you window, when you need to resize it to full screen:

    UIImageView *img; //create new image
    img = yourImageView;
    [img setOrigin:CGPointMake(yourImageView.frame.origin.x, yourImageView.frame.origin.y+90)]; 
//window size is bigger, so to set an image frame visionary at same place, you need to set origin point lower
    MOEAppDelegate *sharedAppDelegate = (MOEAppDelegate *)[[UIApplication sharedApplication] delegate];
    [sharedAppDelegate.window addSubview:img];
    [UIView animateWithDuration:1 
                     animations:^{
                         [img setFrame:CGRectMake(0, 
                                                  0, 
                                                  320, 
                                                  480)];
                     }];

Note, that your self.view's frame automatically resized when you adding tabBar or navigationBar, and in -(void)viewDidLoad it is NOT resized jet!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文