在 Cocoa 中是否可以通过拖动窗口内的对象来移动窗口?例如:我在一个窗口内有一个 webview,和窗口一样大,所以 setMovableByWindowBackground 显然不起作用。有没有办法单击并拖动 Web 视图并移动整个窗口?
问问题
1739 次
1 回答
5
当然,您只需要使用mouseDragged
. 与此类似的东西应该可以工作:
- (void)mouseDragged:(NSEvent *)theEvent
{
NSPoint currentLocation;
NSPoint newOrigin;
NSRect screenFrame = [[NSScreen mainScreen] frame];
NSRect windowFrame = [self frame];
currentLocation = [NSEvent mouseLocation];
newOrigin.x = currentLocation.x - initialLocation.x;
newOrigin.y = currentLocation.y - initialLocation.y;
// Don't let window get dragged up under the menu bar
if( (newOrigin.y+windowFrame.size.height) > (screenFrame.origin.y+screenFrame.size.height) ){
newOrigin.y=screenFrame.origin.y + (screenFrame.size.height-windowFrame.size.height);
}
//go ahead and move the window to the new location
[self setFrameOrigin:newOrigin];
}
我从这里得到的:http: //www.cocoadev.com/index.pl?SetMovableByWindowBackground
于 2009-12-22T12:54:07.783 回答