0

PDFViewXCode でクラスのカスタム サブクラスを作成しようとしています。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親ウィンドウのサイズで領域を拡大縮小するために何をする必要があるかを誰かが説明できますか?

ビルドして実行できるこのプロジェクトの完全なコードは次のとおりです。

https://github.com/samuelmanzer/MyPDFViewer

4

1 に答える 1

2

PDFView親ウィンドウのサイズを変更する際に のサイズを変更する必要があることを理解しています。これを達成するには2つの方法があります

  1. 自動サイズ変更マスクの設定
    • Autoresizing マスクをプログラムで設定しても、ビューの autolayout がオンになっているため、これは効果的ではありません (Xcode 5 でデフォルトでプロジェクトを作成すると、xib ファイルはデフォルトで autolayout に設定されます)。Xcode の MainMenu.xib ファイルの [ユーティリティ] ペインにある [ID と種類] タブの [自動レイアウトを使用] チェックボックスをオフにして、自動レイアウト機能をオフにします。
    • コード行を追加して、MyPDFView の-(void)awakeFromNibを変更します。[self setFrame:[self superview].bounds];
  2. レイアウト制約を定義して Autolayout を使用する
于 2013-11-19T18:03:06.403 に答える