2011-11-11 43 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