(Cocoa)带有IKImageBrowserView的NSScrollView滚动到底部

Wri*_*sCS 3 macos cocoa nsscrollview ikimagebrowserview osx-elcapitan

我正在使用一个IKImageBrowserView显示图像网格.我没有任何设置点或偏移的代码或以编程方式滚动任何内容.我只是有代码列出了一个充满图像的目录的内容,并在图像浏览器中显示它们.

启动应用程序后,滚动视图将无条件地滚动到图像网格的底部.在此之后的几秒钟内,如果您尝试使用鼠标向上滚动,则滚动条会出现故障并仍尝试滚动到底部.此后,问题停止,用户可以正常滚动.

在El Capitan之前,自动滚动没有发生.

同样,没有代码,滚动NSSrcollView或设置contentOffset,或者scrollToRect,scrollToVisibleRect.

话虽如此,我已经尝试在图像加载后设置这些值但没有成功.

问题1:有没有人经历过这种用NSScrollViewIKImageBrowserView在埃尔卡皮坦(或可能的任何版本的Mac OS)?

问题2:有没有办法调试为什么会发生这种情况或如何让它自动停止滚动?


这个解决方案最终为我工作.务必正确连接插座.

.H

@interface WCSScrollView : NSScrollView

@end
Run Code Online (Sandbox Code Playgroud)

.M

@class IKImageBrowserView;

@interface WCSScrollView ()
@property (strong) IBOutlet NSClipView * scrollerClipView;
@property (strong) IBOutlet IKImageBrowserView * imageBrowser;
@end

@implementation WCSScrollView

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
}

- (void)resizeSubviewsWithOldSize:(NSSize)oldSize {
    NSClipView * clip = self.subviews[0];
    self.imageBrowser = (IKImageBrowserView*)clip.subviews[0];
}

@end
Run Code Online (Sandbox Code Playgroud)

查看层次结构

Pet*_*isu 5

您需要子类化NSScrollView

.H

#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>

// This class fixes a glitch with the
// ikimagebrowserview
// http://stackoverflow.com/questions/33643289/cocoa-nsscrollview-with-ikimagebrowserview-scrolls-to-bottom

@interface IKImageBrowserScrollFixScrollView : NSScrollView

@end
Run Code Online (Sandbox Code Playgroud)

.M

#import "IKImageBrowserScrollFixScrollView.h"

@implementation IKImageBrowserScrollFixScrollView

- (void)resizeSubviewsWithOldSize:(NSSize)oldSize {

    NSClipView * clipView;
    for (NSView * v in self.subviews) {
        if ([v isKindOfClass:[NSClipView class]]) {
            clipView = (NSClipView *)v;
            break;
        }
    }

    IKImageBrowserView * imageBrowser;
    for (NSView * v in clipView.subviews) {
        if ([v isKindOfClass:[IKImageBrowserView class]]) {
            imageBrowser = (IKImageBrowserView *)v;
            break;
        }
    }

    NSRect r = imageBrowser.frame;
    [super resizeSubviewsWithOldSize:oldSize];
    imageBrowser.frame = r;

}

@end
Run Code Online (Sandbox Code Playgroud)