繁体   English   中英

Cocoa PDFView没有调整大小

[英]Cocoa PDFView does not resize

我试图在XCode中创建PDFView类的自定义子类。 我在InterfaceBuiler中向我的窗口添加了一个PDFView实例,并为子类创建以下文件:

MyPDFView.h:

#import <Quartz/Quartz.h>

@interface MyPDFView : PDFView

-(void)awakeFromNib;
-(void)mouseDown:(NSEvent *)theEvent;

@end

MyPDFView.m:

#import "MyPDFView.h"

@implementation MyPDFView

-(void)awakeFromNib
{
    [self setAutoresizingMask: NSViewHeightSizable|NSViewWidthSizable|NSViewMinXMargin|NSViewMaxXMargin|NSViewMinYMargin|NSViewMaxYMargin];
    [self setAutoScales:YES];
}

- (void)mouseDown:(NSEvent *)theEvent
{
    unsigned long mask = [self autoresizingMask];
    NSLog(@"self autoresizingMask: %lu",mask);
    NSLog(@"NSViewHeightSizable: %lu",mask & NSViewHeightSizable);
    NSLog(@"NSViewWidthSizable: %lu",mask & NSViewWidthSizable);
    NSLog(@"self setAutoScales: %@",[self autoScales] ? @"YES" : @"NO");
    NSView* sv = [self superview];
    NSLog(@"superview autoresizesSubviews: %@",[sv autoresizesSubviews] ? @"YES" : @"NO");
    NSSize frame_dims = [self frame].size;
    NSLog(@"Frame: (%f,%f)",frame_dims.width,frame_dims.height);
    NSSize bounds_dims = [self bounds].size;
    NSLog(@"Bounds: (%f,%f)",bounds_dims.width,bounds_dims.height);
    NSSize sv_frame_dims = [sv frame].size;
    NSLog(@"Superview Frame: (%f,%f)",sv_frame_dims.width,sv_frame_dims.height);
    NSSize sv_bounds_dims = [sv bounds].size;
    NSLog(@"Superview Bounds: (%f,%f)",sv_bounds_dims.width,sv_bounds_dims.height);
    [super mouseDown:theEvent];
}
@end

但是,尽管设置了所有内容并且单击PDFView区域时触发的后续NSLog语句确认对象应该调整大小,但调整窗口大小不会调整PDFView大小。 任何人都可以解释我需要做些什么来使PDFView区域与父窗口的大小PDFView缩放?

这个项目的完整代码将允许您构建和运行它在这里:

https://github.com/samuelmanzer/MyPDFViewer

我了解您的要求是在调整父窗口大小时调整PDFView大小。 有两种方法可以实现这一目标

  1. 设置自动调整蒙版
    • 即使您以编程方式设置了自动调整遮罩,但这对于视图的自动布局已打开无效(当您在Xcode 5上默认创建项目时,默认情况下会将xib文件设置为自动布局)。 通过取消选中Xcode中“实用工具”窗格中“身份和类型”选项卡中的“使用Autolayout”复选框来关闭Autolayout功能,以获取MainMenu.xib文件。
    • 通过添加代码行修改MyPDFView的- (void)awakeFromNib [self setFrame:[self superview].bounds];
  2. 通过定义布局约束来使用Autolayout

暂无
暂无

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

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