第18章 Images and Mouse Events
来源:互联网 发布:剧情av知乎 编辑:程序博客网 时间:2024/05/19 12:40
第18章 Images and Mouse Events
本章主要介绍如何将一个image放到view中,以及使用鼠标的响应事件完成重新绘制图像的功能。
在上一章custom view的基础上,响应菜单栏的open事件,打开一个openPanel,完成选择图像文件,并将该图像存储到内部变量中。在自己创建的strechview绘制自己时,通过响应鼠标的事件,完成在选定位置,选定大小的矩形中绘制选择的图像文件。
在challenge中,又一次使用NSBezierPath,完成在任意位置绘制圆的功能。
view绘制图像函数
- (void)drawRect: (NSRect)rect {
// Drawing code here.
NSRect bounds = [self bounds];
[[NSColor greenColor] set];
[NSBezierPath fillRect:bounds];
[[NSColor whiteColor] set];
[path stroke];
NSRect drawingOval = [self currentOvalRect];
ovalPath = [NSBezierPath bezierPathWithOvalInRect:drawingOval];
[ovalPath closePath];
[[NSColor redColor] set];
[ovalPath stroke];
if(image)
{
NSRect imageRect;
imageRect.origin = NSZeroPoint;
imageRect.size = [image size];
NSRect drawingRect = [self currentRect];
[image drawInRect:drawingRect fromRect:imageRect operation:NSCompositeSourceOver fraction: opacity];
}
}
文件名:imagefun_upload.zip
文件大小:4 KB
下载地址:http://1000eb.com/8upe
文件大小:4 KB
下载地址:http://1000eb.com/8upe
- 第18章 Images and Mouse Events
- Cocoa Programming for Mac OS X 第十八章(Images and Mouse Events)摘录
- System Events and Mouse Messages
- Mouse wheel events, event filters, and QScrollArea
- Mouse Events
- test the mouse events
- D3 Mouse Events
- Professional JS(13.4.3Mouse and Wheel/Keyboard and Text/composition/Mutation/HTML5 Events[part])
- adds events to the mouse
- iOS编程第四版第12,13章---Touch Events and UIResponder, UIGestureRecognizer and UIMenuController
- 第3章 Raster Images
- DragManager prevents mouse events of children *Updated*
- 第12张 Touch Events and UIResponder翻译
- key and mouse simulation
- QML Color and Images
- Docker Images and Registry
- Properties, methods and events
- Events and Delegates simplified
- 第14章 Using Notifications
- 第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)