简体   繁体   English

调整窗口大小时,NSScrollView中的NSScroller不会更改位置(在Swift中)

[英]NSScroller inside a NSScrollView does not change position when resizing the window (in Swift)

I have created a NSView with Interface Builder (Xcode 6.1). 我已经使用Interface Builder(Xcode 6.1)创建了一个NSView。 The NSView has constraints for each direction. NSView对每个方向都有约束。 When changing the window-size with the mouse manually, the NSView is getting a new size and the NSScroller gets a new position at the correct right border of the window, as expected. 手动更改窗口大小时,如预期的那样,NSView将获得新的大小,而NSScroller将在窗口的正确右边界获得新的位置。

When I set the window size manually (before it is made visible) with 当我手动设置窗口大小时(在可见之前)

myTextView.enclosingScrollView!.window!.setFrame(theRect)

or with 或搭配

myTextView.window!.setFrame(theRect)

Then the window resizes well (as soon as it becomes visible), the NSTextView resizes also but the NSScroller (which is automatically part of the NSTextview and has not been created or modified seperately) does not move but stands in the middle of the ScrollView at its old position. 然后窗口调整好大小(一旦可见),NSTextView也调整大小,但是NSScroller(它是NSTextview的一部分,并且没有单独创建或修改)不会移动,而是位于ScrollView的中间它的旧位置。 The Text entered in the NSScrollView uses the full size and floats behind the NSScroller, which seams to stand in top of the text. 在NSScrollView中输入的文本将使用完整大小,并漂浮在NSScroller的后面,而NSScroller接缝位于文本的顶部。

In the case, the Window is visible before setting the Window Size, then the scroll-view is truncated at the right side or bottom side. 在这种情况下,在设置“窗口大小”之前“窗口”是可见的,然后滚动视图在右侧或底部被截断。

When I change the window manually, after settzing the size and getting this behaviour, the NSScroller jumps to it's right position and the NSTextView is not longer truncated. 当我手动更改窗口时,在调整大小并获得此行为后,NSScroller会跳至其正确位置,并且NSTextView不再被截断。 So changing the Window Size manually does something more that I do programmatically. 因此,手动更改“窗口大小”可以完成一些编程方面的工作。

What must I do, that the Scroller moves with the NSView, like changing the Size of the Window with the Mouse? 我该怎么做,使Scroller与NSView一起移动,就像用鼠标更改Window的大小一样?

This is a typically problem when calling UI-functions from a background thread. 从后台线程调用UI函数时,这通常是一个问题。

It can besolved, when calling from main-thread or forcing to called by the main-thread with this command: 当使用以下命令从主线程调用或强制由主线程调用它时,可以解决该问题:

dispatch_async(dispatch_get_main_queue())
{
    // Place the UI Functions here
}

Please have a look at: Open File Dialog crashes in Swift 请看一下: Swift中的“打开文件”对话框崩溃

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM