设备旋转时,未选择的选项卡栏视图控制器不会调整大小

发布于 2024-11-03 17:11:31 字数 877 浏览 0 评论 0 原文

我在使我的应用程序与 iPad 兼容时遇到问题。

我有一个自定义选项卡栏的实现,基于这里的帖子 http://www.wiredbob.com/blog/2009/4/20/iphone-tweetie-style-navigation-framework.html

除了设备处于关闭状态外,一切正常旋转。当前选定的视图可以完美旋转和调整大小。所有其他视图都会旋转,但不会调整大小以填充空间。右手边有一根巨大的白色柱子。

我尝试添加

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.autoresizesSubviews = YES;

到选项卡控制器视图。

我已将类似的代码添加到选项卡的视图 viewDidLoad 方法中。

我尝试让 willRotateToInterfaceOrientation 调用所有子视图旋转方法,但仍然没有成功。

在此阶段,任何建议都将受到欢迎。我希望我没有忽略一些显而易见的事情,但我可能会忽略。我已经研究了几个小时了

屏幕截图 1 - 旋转所选选项卡效果很好 请参阅下面的其他选项卡的外观喜欢>
屏幕截图 <img src=

I'm having problems making my app iPad compatible.

I have an implementation of a custom Tab Bar, based on the post here http://www.wiredbob.com/blog/2009/4/20/iphone-tweetie-style-navigation-framework.html

That all works fine apart from when the device is rotated. The currently selected view rotates and resizes perfectly. Every other view rotates but does not resize to fill the space. There is a large white column down the right hand side.

I've tried adding

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.autoresizesSubviews = YES;

to the tab controller view.

I've added similar code to the tab's views viewDidLoad methods.

I've tried to make the willRotateToInterfaceOrientation call all the subviews rotation methods but still no luck.

Any suggestions would be more than welcome at this stage. I'm hoping i'm not overlooking something obvious but i might be. I've been at it for a few hours now

Screenshot 1 - Rotating the selected tab works fine see below for what the other tabs look like
Screenshot Screenshot of the result of rotating and selected a different tab

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

终弃我 2024-11-10 17:11:31

好的我解决了这个问题。

我所要做的就是手动对所有子视图调用调整大小。 - 我向每个子视图添加了一个changeFrameSize函数(只是为了让代码看起来更好一点)

哦,当添加视图作为子视图时总是使用belowSubView方法 -

[self.view insertSubview:viewController.view belowSubview:tabBar];

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[(ViewControllerClass *)[viewControllers objectAtIndex:0] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
[(ViewControllerClass *)[viewControllers objectAtIndex:1] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
[(ViewControllerClass *)[viewControllers objectAtIndex:2] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
}

所以因为选定的视图控制器总是旋转并调整大小到正确的大小,一旦旋转和调整,我只需将相同的参数传递给子视图,这样它们也会调整大小。

Ok I Solved this problem.

What I had to do was manually call a resize on all the sub views. - i added a changeFrameSize function to each sub view (just so it made the code look a little nicer)

Oh and when adding views as sub views always use belowSubView method -

[self.view insertSubview:viewController.view belowSubview:tabBar];

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[(ViewControllerClass *)[viewControllers objectAtIndex:0] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
[(ViewControllerClass *)[viewControllers objectAtIndex:1] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
[(ViewControllerClass *)[viewControllers objectAtIndex:2] changeFrameSize:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.width] height:[NSNumber numberWithFloat:self.selectedViewController.view.bounds.size.height]];
}

So because the selected view controller was always rotated and resized to the correct size, once it had rotated and adjusted i simply passed the same parameters to the sub views so they would resize too.

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