gpt4 book ai didi

objective-c - NSScrollView 在 Cocoa 中底部有空间并且滚动条始终位于底部

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

我创建了一个 NSScrollView 并在其中添加了自定义 NSVIew,但运行时,它始终在底部有一个空格,并且滚动条始终位于底部。现在,我想要 ScrollView 适合自定义 View ,并且滚动条始终位于顶部。这是我的代码:

 float label_Y;
float textfield_Y;
float heightView;
-(void) createTableWiFi: (int) number
{

heightView = (25 + 30) * number;

guiView = [[NSView alloc] initWithFrame:NSMakeRect(0,0,600, heightView)];

label_Y = heightView;
textfield_Y = heightView ;
[[ScrollView verticalScroller] setFloatValue:0.0];
[[ScrollView contentView] scrollToPoint:NSMakePoint(0.0, heightView)];
int i;
for(i=1; i<=number;i++)
{

ssidtxt = [[NSTextField alloc] initWithFrame:NSMakeRect (50,textfield_Y,130,25)];
[ssidtxt setBezelStyle:NSTextFieldSquareBezel];
ssidtxt.tag=i;
[ssidtxt setAutoresizingMask:NSViewWidthSizable];

[guiView addSubview:ssidtxt];

[ssidtxt release];


keytxt = [[KSPasswordField alloc] initWithFrame:NSMakeRect (200,textfield_Y,130,25)];
[guiView addSubview:keytxt];
[keytxt release];

textfield_Y -=30;
}
prototype= [[NSButtonCell alloc] init];
[prototype setTitle:@""];
[prototype setButtonType:NSRadioButton];

NSRect matrixRect = NSMakeRect(500, textfield_Y +25 , 50,25 *(i-1));
myMatrix = [[NSMatrix alloc] initWithFrame:matrixRect
mode:NSRadioModeMatrix
prototype:(NSCell *)prototype
numberOfRows:i-1
numberOfColumns:1];
[myMatrix setCellSize:NSMakeSize(50, 30)];

[myMatrix setAction:@selector(radioButtonClicked:)];
NSArray *cellArray = [myMatrix cells];

[guiView addSubview:myMatrix];

[ScrollView setDocumentView :guiView];
[[ScrollView verticalScroller] setFloatValue:0.0];
[[ScrollView contentView] scrollToPoint:NSMakePoint(0.0, heightView)];
[guiView release];
}

欢迎提出任何建议。提前致谢

最佳答案

不要这样做。

[[ScrollView verticalScroller] setFloatValue:0.0];

您可能会强制它导致一些不一致。如果您的滚动条位置没有更新(我不太确定这是否是您的问题),请使用

[ScrollView reflectScrolledClipView:[ScrollView contentView]];

另请阅读Cocoa coding guidelines 。这是一篇相对较短的文章,但非常值得。

关于objective-c - NSScrollView 在 Cocoa 中底部有空间并且滚动条始终位于底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18187031/

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