小编Sim*_*lli的帖子

在调整窗口大小时固定NSScrollView的文档视图

这看起来像是一个微不足道的问题,但它一直困扰着我.

我有一个包含滚动视图的窗口.通常,滚动视图的文档视图垂直大于剪辑视图,因此您可以使用垂直滚动条查看滚动视图中的所有内容.

当我调整窗口大小时,我会重新计算滚动视图的documentView中内容的大小(因为滚动视图可以变得更薄,这可能使documentView的高度增长).然而,副作用是,在调整窗口大小时,documentView会使底部可见边缘与剪辑视图的下边缘齐平(也就是说,它确保最后一行文本始终可见).这是一种奇怪的效果,因为通常,窗口使文档视图的顶部可见边缘与剪辑视图的顶部边缘齐平(即,文档视图中最顶部的文本行保持固定在顶部).

所以,我最初想解决这个问题只是为了实现一个windowDidResize:或windowWillResize:toSize:notification,注意旧窗口框架高度和新高度之间的差值,然后只需滚动滚动视图就可以了滚动视图的顶行固定在顶部.

但是,出于某种原因,这似乎不起作用.它几乎可以工作,但一些调整大小的增量似乎是一个像素关闭,如果你足够快地调整窗口大小,它有时是~10像素关闭.因此效果是滚动视图的顶行几乎固定在顶部,但并不完全,这让人分心.

有一个更好的方法吗?这是相关的代码:

- (void)windowDidResize:(NSNotification *)notification;
{
    if ([notification object] == mainWindow) {
        CGFloat currentWindowHeight = [mainWindow frame].size.height;

        // previousWindowHeight is an ivar
        NSNumber *heightDeltaNum = [NSNumber numberWithFloat:(currentWindowHeight - previousWindowHeight)];
        previousWindowHeight = currentWindowHeight;
        [[NSNotificationCenter defaultCenter] postNotificationName:@"AFSnapScrollView" object:heightDeltaNum];
    }
}

- (void)snapScrollViewNotification:(NSNotification *)theNotification;
{
    [self snapScrollView];

    NSNumber *heightDeltaNum = [theNotification object];

    CGFloat newY = [[tagScrollView documentView] visibleRect].origin.y - [heightDeltaNum floatValue];
    NSPoint pointToScroll = NSMakePoint(0,newY);
    [[tagScrollView documentView] scrollPoint:pointToScroll];
}

- (void)snapScrollView;
{

    [...]

    // adjust …
Run Code Online (Sandbox Code Playgroud)

cocoa nsscrollview

4
推荐指数
1
解决办法
2442
查看次数

使用ARC编译时的ImageKit错误和警告

我正在尝试将我的项目转换为ARC,但我在我的项目中使用ImageKit.ARC重构工具和我自己的手动重构都会在ImageKit头文件中使用ARC生成错误和警告,这些文件已包含在我自己的源文件中.它们看起来像这样:

In file included from /Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Headers/ImageKit.h:9:
In file included from /Volumes/Macintosh HD/Users/simone/Development/AFController.h:12:
In file included from /Volumes/Macintosh HD/Users/simone/Development/AFOperation.m:10:
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Headers/IKImageBrowserView.h:176:14: error: the current deployment target does not support automated __weak references [4]
     IBOutlet __weak NSScroller*                   _horizontalScroller;
              ^
<built-in>:115:31: note: instantiated from:
 #define __weak __attribute__((objc_ownership(weak)))
                               ^
In file included from /Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Headers/ImageKit.h:9:
In file included from /Volumes/Macintosh HD/Users/simone/Development/AFController.h:12:
In file included from /Volumes/Macintosh HD/Users/simone/Development/AFOperation.m:10:
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Headers/IKImageBrowserView.h:177:14: error: the current deployment target does not support automated __weak references [4]
     IBOutlet __weak id                            _delegate;
              ^
<built-in>:115:31: …
Run Code Online (Sandbox Code Playgroud)

cocoa imagekit automatic-ref-counting

3
推荐指数
1
解决办法
1087
查看次数