Windows and Window Controllers in OS X Tutorial学习笔记

learn from:Windows and Window Controllers in OS X Tutorial

Overview

window is the isntance of the NSWindow class, and the associated controller object is an instance of the NSWindowController class.In a well-designed app,you typically see a one-to-one relationship between a window and its controller.

Learn What

we’ll learn about:

  • Windows and window controllers
  • The Document architecture
  • NSTextView
  • Modal windows
  • The menu bar and menu items

Document Architecture

创建工程的时候,勾选Create Document-Based Application.
A document is a container for data in memory that you can view in a window.Eventually,it can be written to or read from a disk or iCloud.

  • NSDocument: Creates,presents and stores document data
  • NSWindowController:Manages a window in which a document is displayed
  • NSDocumentController: manages all of the document objects in the app

关系如图所示(Picture from博客):
DocArchitecture
(图来自作者Gabriel Miro)

In Document.m
// for writing
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
    [NSException raise:@"UnimplementedMethod" format:@"%@ is unimplemented", NSStringFromSelector(_cmd)];
    return nil;
}
// for read
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError {
    [NSException raise:@"UnimplementedMethod" format:@"%@ is unimplemented", NSStringFromSelector(_cmd)];
    return YES;
}

保存与打开document不在本教程范围

Window Position

Note: 在OS X中,坐标体系跟iOS有些许区别,采取的是(x,y)左下角原点(0,0)坐标,即垂直方向的值从上到下是递减的,而iOS中是左上角原点坐标(0,0),y方向的值从上到下是递增的。
在OS X中,如果想要看到窗口初始位置的修改,不仅需要rebuild跟run,还需要关闭之前的窗口打开新窗口。

visibleFrame excludes the areas taken by the dock and menu bar. If you don’t take this into account, you might end up with the dock obscuring part of your window.
When you enable dock and menu hiding, visibleFrame may still be smaller than frame, because the system retains a small boundary area to detect when to show the dock.

visibleFrame与frame: visibleFrame不包括dock和menu bar.frame的坐标体系是有将dock和menu bar计算在内。所以当存在dock或者menu bar的时候,visibleFrame的坐标会比frame的坐标小。但当关闭dock和menu bar的时候,visibleFrame 仍有可能会比frame小,原因在于系统仍旧保留的了一个小的区域显示dock。

NSWindowController has a window property and NSWindow has a screen property. You use these two properties to access the geometry of the window and the screen.

NSWindowController有window属性,NSWindow有一个screen属性。通过这两个属性就可以获取到window和screen的坐标体系。

Note: If you’re an iOS developer, please note that in Cocoa, NSWindow is NOT a subclass of NSView. In iOS, UIWindow is a special subclass, of UIView. UIWindow itself is the root of the view hierarchy, and it’s simply playing the role of the content view.

在iOS中UIWindow继承于UIView,但在OS X中,NSWindow不是继承于NSView,而是NSResponder.

Enable the Font Panel

Format-Font-show Fonts,Ctrol拖拉与First Responder绑定事件,选择orderFrontFontPanel。

获取window demo

NSStoryboard *mainStoryboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
NSWindowController *windowController = [mainStoryboard instantiateControllerWithIdentifier:@"storyboardID"]; // 在windowController中设置storyboardID
NSWindow *window = windowController.window;
// 可在CustomViewController中对内容做一定的定制
CustomViewController *customViewController = window.contentViewController;
// show Modal
[[NSApplication sharedApplication] runModalForWindow:wordCountWindow];
// dismiss
[NSApplication sharedApplication] stopModal];

弹出新窗口

// show
[mainWindow addChildWindow: self.customWindow ordered: NSWindowAbove];
// dismiss
[mainWindow removeChildWindow: self.customWindow];
// 如果不设置nil有个bug,显示弹窗口,设置了过0.5s就自动消失,使用的是performSelector:withObject:afterDelay, bug是任意点击下界面才会消失,而不是自动消失的效果,(r: 目前还不知道是延时操作这边导致的还是其它)
self.customWindow = nil; 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PID控制器是一种常用的自动控制系统设计方法,用于实现稳定的反馈控制。PID控制器的设计基于PID控制的理论原理和调节方法。该理论原理源于控制系统的反馈原理和增益裕度的概念。 PID控制器由比例(P)、积分(I)和微分(D)三个控制部分组成。比例控制部分通过将控制操作量与误差的比例关系来调整系统的动态响应速度。积分控制部分通过累积误差来调整系统的静态稳定性。微分控制部分则通过检测误差变化率来调整系统的快速响应能力。 PID控制器的设计需要根据具体的控制系统要求和性能指标进行调整。通常,比例增益值用于调整系统的稳定性和动态响应速度。积分时间常数用于消除系统的稳态误差。微分时间常数用于减小系统的过冲和抑制振荡。 为了提高PID控制器的性能和稳定性,需要进行PID控制器的调优。调优的目标是找到合适的PID参数值来实现系统的最佳性能。常用的调优方法包括试验法、经验法、模型法和自适应法等。试验法通过实际操作和观察系统响应来调整PID参数。经验法则基于经验公式或经验规则来选择PID参数。模型法则利用控制系统的数学模型和理论分析方法来确定PID参数。自适应法则根据系统的实时响应来动态调整PID参数。 PID控制器的理论设计和调优是控制工程领域的重要课题,对于实现自动控制系统的稳定和优化具有重要意义。充分理解PID控制器的原理和调优方法,能够有效设计和优化控制系统,提高系统的性能和稳定性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值