【发布时间】:2024-01-10 18:43:02
【问题描述】:
按下按钮时,移动鼠标,不要拖动窗口。
按下按钮移动时,不要移动窗口
按钮添加类ButtonStyle。按下鼠标改变背景图片。
-(void)mouseDown:(NSEvent *)theEvent{
[self setImage:[NSImage imageNamed:@"closeDown.png"]];
}
这里是拖动窗口的代码
- (void)mouseDown:(NSEvent *)theEvent
{
NSRect windowFrame = [self frame];
initialLocation = [NSEvent mouseLocation];
initialLocation.x -= windowFrame.origin.x;
initialLocation.y -= windowFrame.origin.y;
}
- (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;
if( (newOrigin.y+windowFrame.size.height) > (screenFrame.origin.y+screenFrame.size.height) ){
newOrigin.y=screenFrame.origin.y + (screenFrame.size.height-windowFrame.size.height);
}
[self setFrameOrigin:newOrigin];
}
【问题讨论】:
-
点击按钮移动窗口不动。我移动窗口。
-
只有当 mouseDown 在按钮上时才移动窗口?或者当鼠标在窗口中的任意位置时?
-
代码下载。当按钮移动时,不要移动窗口
-
如果您有可以为您翻译的朋友,请这样做,因为您当前形式的帖子是零意义的。
-
对不起,我不想在按下按钮移动时拖动窗口,ButtonTab示例,我更新了。我们该怎么办。明白了吗?
标签: objective-c macos cocoa osx-lion