设置 nsview 大小
我正在开发我的应用程序的 GUI。我有一个嵌入到 NSScrollView 中的主视图。当用户单击按钮时,其内容会刷新。然后,它确定显示内容所需的高度。视图显示得不好,有很多小故障,项目显示两次......我知道问题是当我使用 [self setBounds: ...] 设置视图大小时。你知道我如何改变视图大小吗?这是代码:
CGFloat allHeight= 0.0;
for(int i=0; i < [publications count]; i++) {
Publication* pub= [publications objectAtIndex:i];
CGFloat pubHeight= [self heightForTextStorage:[pub statusContent] withWidth:300];
if (pubHeight < 100.0)
pubHeight= 100.0;
allHeight += pubHeight;
}
if (allHeight > [[self superview] bounds].size.height) {
NSRect allBounds= self.frame;
allBounds.size.height= allHeight;
[self setFrame:allBounds];
}
else {
NSRect allBounds= [[self superview] bounds];
[self setFrame:allBounds];
}
提前致谢!
I'm working on the GUI of my application. I have a main view embedded into a NSScrollView. Its content is refreshed when the user clicks a button. It then determines the required height for displaying the content. The view is not displayed well, there are a lot of glitches, of items displayed twice... I know the problem is when I set the view size with [self setBounds: ...]. Do you know how I can change the view size? Here is code:
CGFloat allHeight= 0.0;
for(int i=0; i < [publications count]; i++) {
Publication* pub= [publications objectAtIndex:i];
CGFloat pubHeight= [self heightForTextStorage:[pub statusContent] withWidth:300];
if (pubHeight < 100.0)
pubHeight= 100.0;
allHeight += pubHeight;
}
if (allHeight > [[self superview] bounds].size.height) {
NSRect allBounds= self.frame;
allBounds.size.height= allHeight;
[self setFrame:allBounds];
}
else {
NSRect allBounds= [[self superview] bounds];
[self setFrame:allBounds];
}
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我再次找到了解决方案。我正在更改 drawRect 方法内的 nsview 边界(尽管这是在进行任何绘图之前)。我把这段代码放在其他地方,现在它可以正常工作了。
Once again I found the solution. I was changing the nsview bounds inside the drawRect method (although it was before doing any drawing). I put that piece of code elsewhere and now it's perfectly working.