SplitView 详细视图返回错误的视图框架?

发布于 2024-10-20 05:39:47 字数 641 浏览 5 评论 0原文

我在 iPad 应用程序中使用 splitView。详细信息视图中有 2 个子视图,它们根据详细视图边界绘制自己。 问题是,即使 ipad 处于横向模式,它们也总是将自己绘制在 (1024, 768) 中。

顺便说一句 - 如果我在纵向模式下打电话,然后旋转 ipad,它们会缩放到(706,768)。

我已经检查了它创建时的详细视图框架和边界(在视图确实加载方法中),在这两种情况下我都得到了:

NSLog(@"screen frame = %@",NSStringFromCGRect(self.view.frame));
NSLog(@"screen bounds = %@",NSStringFromCGRect(self.view.bounds));

在调试窗口中我得到:

2011-03-03 10:58:19.376 English Club[63347:207] screen frame = {{0, 0}, {768, 1024}}
2011-03-03 10:58:19.382 English Club[63347:207] screen bounds = {{0, 0}, {768, 1024}}

我无法找出问题所在。有人可以帮助我吗?

感谢您的任何帮助。

I am using a splitView in iPad app. the detail view has 2 subView in it that draws themselves according to the etail view bounds.
the problem is that they always draw themselves in (1024, 768) even when the ipad is in landscape mode.

BTW - if i call then in portrait mode and then rotate the ipad they do scale to (706,768).

I have checked the detail view frame and bounds as it created (in the view did load method) and in both cases i get this:

NSLog(@"screen frame = %@",NSStringFromCGRect(self.view.frame));
NSLog(@"screen bounds = %@",NSStringFromCGRect(self.view.bounds));

In the debug window I get:

2011-03-03 10:58:19.376 English Club[63347:207] screen frame = {{0, 0}, {768, 1024}}
2011-03-03 10:58:19.382 English Club[63347:207] screen bounds = {{0, 0}, {768, 1024}}

I cannot find out where the problem is. Can anyone help me?

Thanks for any help.

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

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

发布评论

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

评论(6

_失温 2024-10-27 05:39:47

在 viewDidLoad 中,视图不应该具有其实际大小。这是稍后通过布局方法设置的。但这不应该阻止您:) 如何设置自动调整大小蒙版?如果设置正确,一切都应该没问题。

In viewDidLoad the view is not supposed to have its real size. That is set up later by layout methods. But that shouldn't stop you :) How do you set your autoresizing mask? If you have set it correctly, everything should be ok.

猛虎独行 2024-10-27 05:39:47

如果你等待 -(void)viewDidLayoutSubviews
它将有合适的尺寸

if you wait for -(void)viewDidLayoutSubviews
it will have the right size

太阳哥哥 2024-10-27 05:39:47

我目前正在编写一个 UISplitViewController 应用程序,很失望地发现更改详细信息或主视图的大小是被禁止的。它完全负责这些子帧的大小。

与 UINavigationController 和 UITabBarController 一样,UISplitViewController 是一个“容器”视图控制器,它调整其子视图以适应其用途。

函数 self debugDumpTheFrames 打印出 uisplitviewcontroller 的框架及其两个子框架。我打印 splitViewController 的 viewDidLoad 中的帧,并设置一个计时器,在 2 秒后再次调用此函数(在此期间我什么也不做):

[self debugDumpTheFrames];
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(debugDumpTheFrames) userInfo:nil repeats:NO];

如果我们查看输出,我们可以看到在 viewdidload 之后的某个时间,UISplitViewController 已更改了其子视图的框架。

size of splitviewcontrollers view frame {{0, 0}, {748, 1024}}
size of splitviewcontrollers detail view frame {{0, 0}, {768, 1024}}
size of splitviewcontrollers master view frame {{0, 0}, {768, 1024}}

size of splitviewcontrollers view frame {{0, 0}, {748, 1024}}
size of splitviewcontrollers detail view frame {{321, 0}, {703, 748}}
size of splitviewcontrollers master view frame {{0, 0}, {320, 748}}

我不确定它到底在哪里调整大小;但 uisplitviewcontroller 是这些框架的老板,它们是私有财产,因此触摸它们将被商店拒绝。

I am currently writing a UISplitViewController app, and was disappointed to find out changing the the size of the detail or master view is forbidden. It is totally in charge of the size of the those sub frames.

Like UINavigationController and UITabBarController, UISplitViewController is a 'container' view controller, and it shapes it's subviews to fit it's purposes.

The function self debugDumpTheFrames prints out the uisplitviewcontroller's frame and it's two subframes. I print the frames in the splitViewController's viewDidLoad, and set a timer to call this function a second time 2 seconds later (during which time i Do nothing):

[self debugDumpTheFrames];
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(debugDumpTheFrames) userInfo:nil repeats:NO];

If we look at the output, we can see that sometime after viewdidload, the UISplitViewController has changed the frames of it's subviews.

size of splitviewcontrollers view frame {{0, 0}, {748, 1024}}
size of splitviewcontrollers detail view frame {{0, 0}, {768, 1024}}
size of splitviewcontrollers master view frame {{0, 0}, {768, 1024}}

size of splitviewcontrollers view frame {{0, 0}, {748, 1024}}
size of splitviewcontrollers detail view frame {{321, 0}, {703, 748}}
size of splitviewcontrollers master view frame {{0, 0}, {320, 748}}

Where exactly it does this resizing I am unsure; but the uisplitviewcontroller is the boss of those frames, and they are private properties so touching them is grounds for rejection from the store.

人生百味 2024-10-27 05:39:47

在 viewWillAppear 而不是 viewDidLoad 中进行操作。

Do your operations in viewWillAppear instead of viewDidLoad.

自在安然 2024-10-27 05:39:47

是的,如果您设置了 Autoresizing 属性,应该没问题。

您可以通过笔尖或代码设置它们,

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

欢呼...

Yes If you have set Autoresizing property it should be ok..

You can set them via nib or by code

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

cheers...

风吹雪碎 2024-10-27 05:39:47

如果您确实需要在 viewDidLoad 中获取正确的宽度,您可以访问分割视图控制器并获取详细视图控制器的宽度。

例如在斯威夫特:

func getDetailViewSize() -> CGSize {
    var detailViewController: UIViewController
    if (self.splitViewController?.viewControllers.count > 1) {
        detailViewController = self.splitViewController?.viewControllers[1] as! UIViewController
    } else {
        detailViewController = self.splitViewController?.viewControllers[0] as! UIViewController
    }
    return detailViewController.view.frame.size
}

If you really do need to get the correct width in viewDidLoad, you can access the split view controller and get the width of the detail view controller.

E.g. in Swift:

func getDetailViewSize() -> CGSize {
    var detailViewController: UIViewController
    if (self.splitViewController?.viewControllers.count > 1) {
        detailViewController = self.splitViewController?.viewControllers[1] as! UIViewController
    } else {
        detailViewController = self.splitViewController?.viewControllers[0] as! UIViewController
    }
    return detailViewController.view.frame.size
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文