- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因为你永远不知道,它可能很有用,我一直在尝试编写一个灵活的 NSSplitView 实验应用程序,其中可以以用户想要的任何方式动态添加和删除 View 。我能做到这一点。
现在我认为能够:
交换 View - 例如,在四 View 窗口中,左上 View 可以拖动到右下角,并且在释放鼠标按钮时, View 将彼此交换。
将 View 拖出 - 例如,在一个四 View 窗口中,如果将左上角 View 拖出其包含的窗口,那么它将成为其右侧的一个窗口,包含该 View 和原始 View 窗口将变成三 View 窗口。
将 View 拖入 - 以便可以将窗口拖入 View 中,关闭窗口并将其 View 添加到拖入的窗口中。
我已经编写了一个程序来完成第一步(灵活设置分割 View )https://github.com/HeadBanging/SplitViewTest但我完全不知道如何做剩下的事情 - 特别是第一点。
如果你看一下代码,你会发现我已经开始了(使用 Apple 和其他地方的教程),但它并没有达到我想要的效果。有人有什么建议吗?
当然,如果您需要的只是为您的项目提供灵活的拆分窗口,那么您就可以使用我的窗口(上面下载),没有使用限制 - 一切顺利。
Willeke 对于如何让拖动发挥作用提出了一些很好的建议,我已按如下方式实现了这些建议(Git 上的完整代码):
#pragma mark Dragging
- (NSImage *)imageRepresentationOfView:(NSView*)draggingView {
BOOL wasHidden = draggingView.isHidden;
CGFloat wantedLayer = draggingView.wantsLayer;
draggingView.hidden = NO;
draggingView.wantsLayer = YES;
NSImage *image = [[NSImage alloc] initWithSize:draggingView.bounds.size];
[image lockFocus];
CGContextRef ctx = [NSGraphicsContext currentContext].graphicsPort;
[draggingView.layer renderInContext:ctx];
[image unlockFocus];
draggingView.wantsLayer = wantedLayer;
draggingView.hidden = wasHidden;
return image;
}
- (void)mouseDown:(NSEvent *)theEvent {
NSSize dragOffset = NSMakeSize(0.0, 0.0);
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType] owner:self];
DebugView *hitView;
NSPoint startLocation = NSMakePoint(0, 0);
NSImage *draggedImage;
BOOL found = NO;
fHitView = nil;
while ((hitView = [[[self subviews] objectEnumerator] nextObject]) && !found) {
if ([hitView isKindOfClass:[DebugView class]] && [(DebugView *)hitView dragEnabled]) { //Change DebugView to Draggable View, and use as container for plugin views
draggedImage = [self imageRepresentationOfView:hitView];
startLocation = hitView.frame.origin;
found = YES;
}
}
if (draggedImage != nil) {
[pboard setData:[draggedImage TIFFRepresentation] forType:NSTIFFPboardType];
[self dragImage:draggedImage at:startLocation offset:dragOffset
event:theEvent pasteboard:pboard source:self slideBack:YES];
}
return;
}
- (void)setHighlighted:(BOOL)value {
isHighlighted = value;
[self setNeedsDisplay:YES];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSPasteboard *pboard = [sender draggingPasteboard];
if ([[pboard types] containsObject:NSFilenamesPboardType]) {
NSArray *paths = [pboard propertyListForType:NSFilenamesPboardType];
for (NSString *path in paths) {
NSError *error = nil;
NSString *utiType = [[NSWorkspace sharedWorkspace]
typeOfFile:path error:&error];
if (![[NSWorkspace sharedWorkspace]
type:utiType conformsToType:(id)kUTTypeFolder]) {
[self setHighlighted:NO];
return NSDragOperationNone;
}
}
}
[self setHighlighted:YES];
return NSDragOperationEvery;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {
[self setHighlighted:NO];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
[self setHighlighted:NO];
DebugView *hitView;
BOOL found = NO;
fHitView = nil;
while ((hitView = [[[self subviews] objectEnumerator] nextObject]) && !found) {
if ([hitView isKindOfClass:[DebugView class]] && [(DebugView *)hitView dragEnabled]) {
found = YES;
}
}
NSView* tempView = [sender draggingSource];
[[[sender draggingSource] superview] replaceSubview:[sender draggingSource] with:hitView];
[self replaceSubview:hitView with:tempView];
[self setNeedsDisplay:YES];
[[[sender draggingSource] superview] setNeedsDisplay:YES];
return YES;
}
- (BOOL)isHighlighted {
return isHighlighted;
}
放置部分部分有效 - 有时 View 准备接受放置,有时则不接受(有人看到我做错了什么吗? - 它应该一直有效,除非被拖放到的 View 是源 View )。
最后一 block 拼图对我来说仍然是个谜(接受掉落,并交换观点)。任何提示将非常感激地接受。
最佳答案
一个 View 可以有一个 super View ,当您将一个 View 添加到另一个 super View 时,该 View 将从原始 super View 中删除。用 View B 替换 View A,然后用 View A 替换 View B 是行不通的,因为 View B 已从其原始 super View 中删除。
自动布局对我来说仍然是一个谜,但首先删除两个 View 然后添加它们似乎可行:
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
[self setHighlighted:NO];
// swap subviews of view1 and view2
NSView *view1 = self;
NSView *view2 = [sender draggingSource];
// find subviews
DebugView *hitView1, *hitView2;
for (hitView1 in [view1 subviews]) {
if ([hitView1 isKindOfClass:[DebugView class]]) {
break;
}
}
for (hitView2 in [view2 subviews]) {
if ([hitView2 isKindOfClass:[DebugView class]]) {
break;
}
}
// swap hitView1 and hitView2
if (hitView1 && hitView2) {
[hitView1 removeFromSuperview];
[hitView2 removeFromSuperview];
[view1 addSubview:hitView2];
NSDictionary *views = NSDictionaryOfVariableBindings(hitView2);
[view1 addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[hitView2]|"
options:0
metrics:nil
views:views]];
[view1 addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[hitView2]|"
options:0
metrics:nil
views:views]];
[view2 addSubview:hitView1];
views = NSDictionaryOfVariableBindings(hitView1);
[view2 addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[hitView1]|"
options:0
metrics:nil
views:views]];
[view2 addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[hitView1]|"
options:0
metrics:nil
views:views]];
return YES;
}
return NO;
}
关于objective-c - 拖动交换 NSView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38787323/
我正在使用 gridstack 来显示我的小部件。拖动和调整大小适用于 gridstack 卡,但当我将卡拖到底部时,卡的容器不会滚动。我想在拖动卡片时滚动那个容器。该容器只是一个 div 元素,所有
我目前正在构建一个多个处理的 slider 小部件,并且目前正在实现手势检测器。我有一个问题,如果您用第二根手指触摸/拖动屏幕,检测器会识别它并调用 onDragUpdate 函数,这是我试图禁用的功
我是 AngularJS 的新手,我对当前的项目有点压力,这就是我在这里问的原因。 我看到 AngularJS 有 ng-dragstart 事件( http://docs.ng.dart.ant.c
关于缩放大图像和平移有什么建议吗?最好内联在页面上。 我一直在使用PanoJS(又名GSV2),但是现在越来越多的人使用iPhone/iPad/Android类型的设备,这个库要么太慢,要么旧版本不支
我在尝试拖动 JPanel 时遇到问题。如果我纯粹在 MouseDragged 中将其实现为: public void mouseDragged(MouseEvent me) { me.getS
我有一个需要与屏幕底部对齐的 ImageButton,当我单击并拖动它时,它会随着我的手指移动一定距离,超过该距离它不会远离原点,而是继续跟随我的手指从原点开始的方向。 当我松手时,按钮必须滑回原点。
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
我需要一个解决方案来实现拖动和缩放,在不使用矩阵的情况下围绕屏幕 onTouch 事件路由 ImageView。我搜索了很多但所有答案都是用矩阵完成的,因为我在屏幕矩阵中有多个对象不适合我,我想拖动和
我需要一些帮助来拖动 UIView 以显示主视图下方的菜单 View 。 我有两个 UIView。menuView - 包括菜单按钮和标签 和 mainView - 位于 menuView 之上。 我
谷歌地图即使设为 true 也不可拖动/拖动。 重现步骤:在新选项卡中加载带有 map 的页面,检查并在不执行任何操作的情况下转到移动 View 。现在在移动 View 中左右上下拖动 map ,它将
我在绘制和缩放 ImageView 时遇到问题。请帮帮我.. 当我画一些东西然后拖动或缩放图像时 - 绘图保留在原处,如您在屏幕截图中所见。而且我只需要简单地在图片上绘图,并且可以缩放和拖动这张图片。
所以我试图模拟鼠标左键单击和鼠标左键释放来执行一些自动拖放操作。 它目前在 C# Winforms(是的,winforms :|)中并且有点笨拙。 基本上,一旦发送了点击,我希望它根据 Kinect
我有一个巨大的 HTML5 Canvas,我希望它像谷歌地图一样工作:用户可以拖动它并始终只看到它的一小部分(屏幕大小)。它只呈现您在屏幕上可以看到的部分。我该怎么做?你有想法吗? 最佳答案 2 个简
我有以下拖放应用程序代码,它在桌面上按预期工作,但是当我想在移动设备上使用该应用程序时,拖动事件无法按预期工作。我知道触摸事件是必需的,但我不确定如何设置它们和实现这些功能。 .object
我正在使用 react-leaflet map ,我用状态改变了很多 map 属性,但是当使用状态来改变拖动属性时它不起作用。 { this.map = map}}
我知道我可以轻松地允许用户在OpenLayers中选择多个功能/几何图形,但是随后我希望使用户能够轻松地同时拖动/移动所有选定的功能。 使用ModifyFeature控件一次只能移动一个要素...是否
我有一个 Windows Phone 运行时应用程序,我使用 xaml 在 map 上显示图钉。 当我拖动 map 时,控件试图保持在相同位置时会出现一些滞后。 任何帮助,将不胜感
我通常不会提出此类问题/答案,但我想我会这样做,因为我已经看到这个问题被问了 20 多次,但没有一个答案真正有效。简而言之,问题是,如果您在可拖动 jQuery 项目内的任何位置有可滚动内容(over
我确信一定有一种简单的方法可以做到这一点,但到目前为止,我已经花了很长时间在各种兔子洞中没有成功。 我有一个支持拖放的 Collection View 。被拖动的单元格有 UIImageView在 c
如何在两个virtualtreeview之间复制以复制所有列,而不仅仅是第一列? 复制前: 复制后: 最佳答案 树控件不保存任何数据。它不包含要显示的列数据,因此无法复制它。而是,当树控件想要显示任何
我是一名优秀的程序员,十分优秀!