2011-11-11 42 views
2

我在写一个简单的MacRuby应用程序。当它的drawRect()被调用时,我有一个NSView在其自身内部绘制图像。NSView NSImage里面 - 如何NSImage不移动它的父视图?

内部的一个NSView继承我的drawRect()有(代码一些其他行中)

image = NSImage.imageNamed("mini_browser") 
image.drawInRect(self.bounds, fromRect: self.frame, operation:NSCompositeSourceOver, fraction:1.0) 

如果我通过my_view.setFrameOrigin([x,y])移动我的子类的NSView其中xy一些价值观,我得到的东西像下面。任何有关为什么会发生这种情况的见解?看起来好像NSImage不会随着包含它的NSView一起移动。

参见实例here.

回答

3

你做错了。从文档中,第二个参数指定:

The source rectangle specifying the portion of the image you want to draw. 
The coordinates of this rectangle must be specified using the image's own 
coordinate system. If you pass in NSZeroRect, the entire image is drawn. 

所以你可能想要传入NSZeroRect作为第二个参数。

+0

非常感谢弗朗西斯! – briangonzalez