gpt4 book ai didi

Xcode,自定义 View - 零帧/边界

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

在我的应用程序中,我需要有一个 splitView 并能够将我自己的 View 插入到 Pane 中。

为此,在界面构建器中,我创建了一个带有两个分隔线(三个 Pane )的 SplitView,并将这三个 Pane 中的“自定义 View ”添加为 IBOutlets 到我相应的 View Controller 。但是,当我查询 IBOutlets 的帧/边界大小时,它们都是 0.00000。

为什么我在 Xcode 中创建的自定义 View 的大小为 0?我该如何解决这个问题?

UPD:查询 Pane 的框架/边界的代码:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.logList = [[LogListViewController alloc] initWithNibName:LOGLISTXIB bundle:nil];
[self logARect:self.leftPane.bounds withName:@"LeftPane bounds"];
[self logARect:self.leftPane.frame withName:@"LeftPane Frame"];
}
}
- (void) logARect:(NSRect) theFrame withName:(NSString *)name {
NSLog(@"%@ frame: %lf, %lf, %lf, %lf", name, theFrame.origin.x, theFrame.origin.y, theFrame.size.width, theFrame.size.height);
}

UPD2同时,当我通过self.view.subviews[0]访问 Pane 时,我得到了正确的大小。

最佳答案

当您尝试获取位置时, View 可能尚未列出。 viewDidLoad in NSViewController?问题指出应该使用 loadView 来修改 View 的布局。这个answer在同一问题中展示了一种使您的 Cocoa 代码类似于 Cocoa-touch 代码的技巧。

关于Xcode,自定义 View - 零帧/边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17317239/

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