第19~20章 Keyboard Events & Drawing Text with Attributes
来源:互联网 发布:剧情av知乎 编辑:程序博客网 时间:2024/06/04 08:11
第19~20章 Keyboard Events & Drawing Text with Attributes
这两章完成了一个功能,响应用户的键盘输入,并把用户输入的字母显示到view中。
第19章主要介绍view如何响应用户的键盘输入。第20章介绍如何将,从键盘得到的字母以特殊的格式显示到view上。
1.一个应用程序可能有多个view。那么,到底哪个view来响应键盘的输入呢?
只有keyView的firstResponder才会响应。但是keyView和first Responsder是可以在view之间切换的。切换的过程如下图所示。
可以通过在nib中设置nextKeyView来完成keyView的切换。
2.对键盘事件的响应通过keyDown等函数来处理,例如:
- (void)keyDown: (NSEvent *)event
{
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
}
Then you need to override the methods that interpretKeyEvents: will call:
- (void)insertText: (NSString *)input
{
// Set string to be what the user typed
[self setString:input];
}
3. 设置格式属性
- (void)prepareAttributes
{
attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:[NSFont fontWithName:@"Helvetica" size:75]
forKey:NSFontAttributeName];
[attributes setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName];
}
4. 将string在view上的以某种格式显示出来
例如,在rect居中显示
- (void)drawStringCenteredIn: (NSRect)r
{
NSSize strSize = [string sizeWithAttributes:attributes];
NSPoint strOrigin;
strOrigin.x = r.origin.x + (r.size.width - strSize.width)/2;
strOrigin.y = r.origin.y + (r.size.height - strSize.height)/2;
[string drawAtPoint:strOrigin withAttributes:attributes];
}
challenge1:在attribute中加入阴影属性。
challenge2: 使用NSFontManager将NSFont转换成“BOLD”格式后,加入attribute中。
另外还介绍了如何产生PDF数据,没有细看。
文件大小:2.26 MB
下载地址:http://1000eb.com/8v1x
- 第19~20章 Keyboard Events & Drawing Text with Attributes
- Drawing styled text with Uniscribe
- Cocoa Keyboard Events - nextkeyview
- Professional JS(13.4.3Mouse and Wheel/Keyboard and Text/composition/Mutation/HTML5 Events[part])
- 第八章 working with events
- 《Data-Intensive Text Processing with MapReduce》第4章-压缩
- Drawing with ASCII art
- Drawing with Data-D3
- Drawing With A Color
- LINK : warning LNK4078: multiple ".text" sections found with different attributes (40000040)
- 第18章 Images and Mouse Events
- Keyboard Events Simulation using keybd_event() function
- Keyboard Events Simulation using keybd_event() function
- Working With System Events
- Events with Dojo
- Drawing Board with AS3.0
- NHibernate文档翻译 第9章----使用AttributesNHibernate.Mapping.Attributes
- Drawing Simple Text:画简单的文本
- 第17章 custom views
- 经典编程书籍(C++, 网络, Windows, Linux)
- Spring3中@Autowired注入的顺序
- 制作blog遇到的问题
- 第18章 Images and Mouse Events
- 第19~20章 Keyboard Events & Drawing Text with Attributes
- 第21章 Pasteboards and Nil-Targeted Actions
- 【算法学习】堆排序(Heap Sorting)
- 第22章 Categories
- 第24章 NSTimer
- 【iOS-cocos2d-X 游戏开发之十三】详细讲解在Xcode中利用预编译并通过Jni调用Android的Java层代码(cocos2dx里访问调用Android函数)!
- 第26章 Creating NSFormatters
- python 得到文件版本信息 公司名和产品名(2)
- 第29章 View Swapping