I am attempting to create a custom subclass of the PDFView
class in XCode. I add a PDFView
instance to my window in InterfaceBuiler and create the following files for the subclass:
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
However, despite setting everything appropriately and the subsequent NSLog
statements that trigger when the PDFView
area is clicked confirming that the object SHOULD be resizing, resizing the window does not resize the PDFView
. Can anyone explain what I need to do to make the PDFView
area scale with the size of the parent window?
The full code for this project that will allow you to build and run it is here:
https://github.com/samuelmanzer/MyPDFViewer