我正在尝试在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
但是,尽管设置了所有内容并且在单击NSLog
区域时触发的后续PDFView
语句确认对象应该调整大小,但调整窗口大小不会调整PDFView
的大小。任何人都可以解释我需要做什么才能使PDFView
区域缩放到父窗口的大小?
此项目的完整代码将允许您构建和运行它:
答案 0 :(得分:2)
我了解您的要求是在调整父窗口大小时调整PDFView
的大小。有两种方法可以实现这个目标
[self setFrame:[self superview].bounds];