當用戶在 MacOS 上調整其大小時,我需要制作主視窗以保留寬度/高度比。
我的第一個想法是處理以下通知:
@interface Override_iOS : NSObject
@end
__strong Override_iOS *_instance;
@implementation Override_iOS
(void)load
{
NSLog(@"[Override_iOS load]");
_instance = [Override_iOS new];
[[NSNotificationCenter defaultCenter] addObserver:_instance
selector:@selector(applicationDidFinishLaunching:)
name:UIApplicationDidFinishLaunchingNotification
object:nil];
}
-(void)applicationDidFinishLaunching:(NSNotification*) notification
{
NSLog(@"[Override_iOS applicationDidFinishLaunching:%@]", notification);
//qDebug() << "applicationDidFinishLaunching handler";
}
@end
并嘗試設定aspectRatio主視窗的屬性,但看起來這段代碼在 MacOS 上不起作用,而只能在 iOS 上運行(至少在我的應用程式中)。
是否有可能在 MacOS 上做這樣的事情?
XCode專案中有選項嗎?
編輯1
我需要這樣的
uj5u.com熱心網友回復:
我對 MacOS 應用程式所做的很少,但這可能是您正在尋找的...
創建一個NSWindow子類:
我的視窗控制器.h
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
@interface MyWindowController : NSWindowController
@end
NS_ASSUME_NONNULL_END
我的視窗控制器.m
#import "MyWindowController.h"
@interface MyWindowController ()
@end
@implementation MyWindowController
- (void)windowDidLoad {
[super windowDidLoad];
// set the aspect ratio here
[self.window setAspectRatio:NSMakeSize(320.0, 640.0)];
}
@end
然后分配視窗控制器的自定義類:

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/521832.html
標籤:目标-c代码uikit
