我目前使用鼠标事件实现了一个简单的选择框,并在鼠标拖动时重绘了一个矩形.这是我的代码:
-(void)drawRect:(NSRect)dirtyRect
{
if (!NSEqualRects(self.draggingBox, NSZeroRect))
{
[[NSColor grayColor] setStroke];
[[NSBezierPath bezierPathWithRect:self.draggingBox] stroke];
}
}
#pragma mark Mouse Events
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint pointInView = [self convertPoint:[theEvent locationInWindow] fromView:nil];
self.draggingBox = NSMakeRect(pointInView.x, pointInView.y, 0, 0);
[self setNeedsDisplay:YES];
}
- (void)mouseDragged:(NSEvent *)theEvent
{
NSPoint pointInView = [self convertPoint:[theEvent locationInWindow] fromView:nil];
_draggingBox.size.width = pointInView.x - (self.draggingBox.origin.x);
_draggingBox.size.height = pointInView.y - (self.draggingBox.origin.y);
[self setNeedsDisplay:YES];
}
- (void)mouseUp:(NSEvent *)theEvent
{
self.draggingBox = NSZeroRect;
[self setNeedsDisplay:YES];
}
Run Code Online (Sandbox Code Playgroud)
参考:http://cocoadev.com/HowToCreateWalkingAnts
问题:
这是最有效的方法吗?如果视图很复杂,那么在主视图上绘制透明视图会更有效,而不是在鼠标拖动期间不断重绘视图(http://www.cocoabuilder.com/archive/cocoa/99877- …
我有一个用VS编码的程序,我正在尝试移植到Xcode.我遇到了几个问题,包括使用lambda函数.由于Xcode使用gcc 4.2,因此不支持C++ 11,我将无法使用任何lambda函数吗?
如果我想从我的笔记本电脑上处理代码而不重写大部分代码,我是否必须安装gcc 4.6并使用终端进行编译?
我想在我的Mac上编译C++ 11功能.到目前为止,我尝试过两种不同的东西.首先,最新的Xcode(4.2)声称支持"C++ 11特性",但是当我尝试编译它时:
#include <iostream>
int main()
{
using namespace std;
int n = [] (int x, int y) { return x + y; }(5, 4);
cout << n << endl;
}
Run Code Online (Sandbox Code Playgroud)
我得到第一个括号([)的错误,"预期表达式".我猜测lambda表达式不包含在新的C++ 11功能中?
然后,作为一个解决方法,我从http://hpc.sourceforge.net/下载了gcc 4.6二进制文件,但是当我使用gcc-4.6时(/usr/local/bin/gcc-4.6 -std = c ++ 0x test.cpp)我得到:
Undefined symbols for architecture x86_64:
"std::cout", referenced from:
_main in cctnMUFF.o
...
Run Code Online (Sandbox Code Playgroud)
我认为这是一个没有找到标准库的问题?
谢谢!