可可PDFView不会调整大小

可可PDFView不会调整大小

本文介绍了可可PDFView不会调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

尽管设置了所有适当内容,但随后的 NSLog 语句,当单击 PDFView 区域时触发,以确认对象应调整大小,调整窗口大小不会调整 PDFView 。谁能解释要使 PDFView 区域缩放与父窗口的大小一样,我需要做什么?

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:

推荐答案

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

I understand that your requirement is to resize the PDFView as you resize the parent window. There are two ways of achieving this


  1. 设置自动调整大小蒙版

    • 即使您已经以编程方式设置了自动调整大小蒙版,因此这无效,因为已为视图打开了自动布局(默认情况下,在Xcode 5上创建项目时,默认情况下会为自动布局
      设置xib文件)。通过取消选中MainMenu.xib文件的Xcode实用工具窗格中身份和类型选项卡中的使用自动布局复选框,来关闭自动布局功能。

    • 修改MyPDFView的-(void)awakeFromNib ,方法是添加代码行 [self setFrame:[self superview] .bounds];

  1. Setting The Autoresizing Mask
    • Even though you have programatically set the Autoresizing mask, this isn’t effective as autolayout has been turned on for your views (When you create projects by default on Xcode 5, the xib files are by default set for autolayout). Turn off the Autolayout feature by unchecking the "Use Autolayout" checkbox in the "Identity and Type" tab in the Utilities pane in Xcode for the MainMenu.xib file.
    • Modify the MyPDFView's -(void)awakeFromNib by adding the line of code[self setFrame:[self superview].bounds];
  • This can be done in the Interface Builder or through code programatically. Please do read Apple Cocoa Auto Layout Guide

这篇关于可可PDFView不会调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:24