코코아 PDFView의 크기가 조정되지 않습니다
-
21-12-2019 - |
문제
사용자 정의 하위 클래스를 만들려고 합니다. PDFView
XCode의 클래스.나는 추가한다 PDFView
인스턴스를 InterfaceBuiler의 내 창에 추가하고 서브클래스에 대해 다음 파일을 만듭니다.
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
부모 창의 크기에 따른 면적 배율?
이 프로젝트를 빌드하고 실행할 수 있는 전체 코드는 다음과 같습니다.
해결책
귀하의 요구 사항이 크기를 조정하는 것임을 이해합니다. PDFView
부모 창의 크기를 조정할 때.이를 달성하는 방법에는 두 가지가 있습니다.
- 자동 크기 조정 마스크 설정
- 자동으로 자동화 된 마스크를 설정했지만 뷰에 대해 자동 금광이 켜져 있기 때문에 효과적이지 않습니다 (Xcode 5에서 기본적으로 프로젝트를 생성 할 때 XIB 파일은 기본적으로 AUTOLAYOUT를 설정합니다).MainMenu.xib 파일에 대한 Xcode의 유틸리티 창에 있는 "ID 및 유형" 탭에서 "자동 레이아웃 사용" 확인란을 선택 취소하여 자동 레이아웃 기능을 끄세요.
- MyPDFView 수정 -(void)awakeFromNib 코드 줄을 추가하여
[self setFrame:[self superview].bounds];
- 레이아웃 제약 조건을 정의하여 자동 레이아웃 사용
- 이는 인터페이스 빌더에서 또는 코드를 통해 프로그래밍 방식으로 수행할 수 있습니다. Apple Cocoa 자동 레이아웃 가이드를 읽어보세요.
제휴하지 않습니다 StackOverflow