Mavericks中的PDFView不会“自动缩放”并始终显示滚动条

时间:2013-10-30 09:35:35

标签: macos cocoa osx-mavericks

我正在创建一个OSX PDF查看器应用程序。在底部有一个水平滚动条,因此用户可以轻松地在页面之间滚动。滚动时,会出现一个小预览窗口,显示该页面的预览。这在OSX 10.7和10.8下工作正常,但在Mavericks 10.9中,“自动缩放”选项确实似乎失去了它的效果。还有一个滚动条(即使将比例设置为不需要滚动条的值)。

关于如何解决这个问题的任何想法?

OSX 10.7和10.8:

OSX 10.7 and 10.8

OSX Mavericks:

OSX Mavericks

设置视图的代码:

- (void)awakeFromNib
{
    [super awakeFromNib];

    [_pdfView setAutoScales:YES];
    [_pdfView setDisplayMode:kPDFDisplayTwoUp];
    [_pdfView setDisplaysPageBreaks:NO];
    [self setWantsLayer:YES];
}

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

    CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
    CGContextSetRGBFillColor(context, 0.227,0.251,0.337,0.8);
    CGContextFillRect(context, NSRectToCGRect(dirtyRect));
}

来自po [self.previewView _subtreeDescription]的视图结构:

$0 = 0x0000000113dcd280 [   A     WLU#] h=&-& v=--& IBPreviewView 0x119554760 f=(730.097,47,300,200) b=(-) => <_NSViewBackingLayer: 0x110a5b800> TIME drawRect: min/mean/max 0.00/0.00/0.00 ms
  [      O  WlU ] h=-&- v=-&- PDFView 0x104cb9c20 f=(10,60,280,130) b=(-) => <_NSViewBackingLayer: 0x114e311a0> TIME drawRect: min/mean/max 0.00/0.00/0.00 ms
    [   AF O  wlU ] h=--- v=--- PDFViewScrollView 0x110a36c60 f=(0,0,280,130) b=(-) => <_NSViewBackingLayer: 0x110a374a0> TIME drawRect: min/mean/max 0.00/0.00/0.00 ms
      [   AF O  wlU ] h=--- v=--- PDFCenteringClipView 0x110a2ba30 f=(0,0,265,130) b=(0.5,0,-,-) => <_NSClipViewBackingLayer: 0x110a42b70> TIME drawRect: min/mean/max 0.00/0.00/0.00 ms
        [   AF O  WLU ] h=--- v=--- PDFMatteView 0x110a28730 f=(0,0,980,683) b=(-) => <_NSViewBackingLayer: 0x110a3b600> TIME drawRect: min/mean/max 0.00/0.00/0.00 ms
          [   A      LU ] h=--- v=--- PDFDisplayView 0x114e309b0 f=(0,0,980,683) b=(-) TIME drawRect: min/mean/max 0.00/0.00/0.00 ms
      [   AF    wlU ] h=--- v=--- NSScroller 0x100766e50 f=(265,0,15,130) b=(-) => <_NSViewBackingLayer: 0x100766e20> TIME drawRect: min/mean/max 0.00/0.00/0.00 ms
  [   AF    wlU ] h=-&- v=-&- NSTextField 0x104c87110 f=(7,27,286,25) b=(-) => <_NSViewBackingLayer: 0x110a5b910> TIME drawRect: min/mean/max 0.00/0.00/0.00 ms
  [   AF    wlU ] h=-&- v=-&- NSTextField 0x110a2ef60 "76 av 152" f=(89,0,115,25) b=(-) => <_NSViewBackingLayer: 0x110a5b970> TIME drawRect: min/mean/max 0.00/0.00/0.00 ms
A=autoresizesSubviews, C=canDrawConcurrently, D=needsDisplay, F=flipped, G=gstate, H=hidden (h=by ancestor), L=needsLayout (l=child needsLayout), U=needsUpdateConstraints (u=child needsUpdateConstraints), O=opaque, P=preservesContentDuringLiveResize, S=scaled/rotated, W=wantsLayer (w=ancestor wantsLayer), #=has surface

我还在_pdfView和self上使用setNeedsLayout:YESsetNeedsDisplay:YES进行了测试,没有任何变化。

有什么建议吗?

3 个答案:

答案 0 :(得分:3)

试试这个:

self.pdfView.autoScales = NO;
self.pdfView.document = _currentDocument
self.pdfView.autoScales = YES;

它对我有用,所以对你有希望。

答案 1 :(得分:0)

在加载pdf文档后尝试这样做:

[self.pdfView setDocument:pdfDoc];
[self.pdfView zoomIn:self];
[self.pdfView setAutoScales:YES];

答案 2 :(得分:0)

似乎是一个错误。通过调整超级视图来解决它。然后它会自动调整大小。

//int widthModifierForMavericksWorkaround = 1;

-(void)refresh
{
    // Ugly workaround for Mavericks, resize view so it updates its scale

    CGSize size = self.frame.size;
    size.width += widthModifierForMavericksWorkaround;
    [self resizeSubviewsWithOldSize:size];

    widthModifierForMavericksWorkaround *= -1;
}