【发布时间】:2020-05-19 14:10:10
【问题描述】:
完整的错误状态:
客户端应用程序错误 - 既不是视图也不是容器 UITargetedPreview 当前在一个窗口中。这是违反 UIDragInteraction API 合同并可能导致严重的视觉故障。 这是一个客户端应用程序错误,很快就会成为一个硬断言。请修理我
自从我将 Xcode 升级到 11.4.1 的那一天,这个不错的小警告就出现了 之前,这个警告从未在我的控制台中弹出。
所以我从一个 UIView 拖到另一个 UIView 中,不涉及 UITableViews 或 UICollectionViews。 我在 UIView 中设置了一个 draginteraction,在接收 UIView 上设置了一个 dropinteraction。
这是来自 UIDragInteraction 委托的代码
- (UITargetedDragPreview *)dragInteraction:(UIDragInteraction *)interaction previewForLiftingItem:(UIDragItem *)item session:(id<UIDragSession>)session {
UIView *view = interaction.view;
CGPoint point = [session locationInView:interaction.view];
UIDragPreviewTarget *target = [[UIDragPreviewTarget alloc] initWithContainer:view center:point];
UIView *previewView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.elementDimension, self.elementDimension)];
[previewView setBackgroundColor:[UIColor colorWithRed:0.98 green:0.97 blue:0.89 alpha:1.00]];
//I've removed the filling of previewView because it has nothing to see with the question
if (@available(iOS 13.0, *)) {
UIPreviewParameters *previewParameters = [[UIPreviewParameters alloc] init];
[previewParameters setBackgroundColor:[UIColor clearColor]];
return [[UITargetedDragPreview alloc] initWithView:previewView
parameters:previewParameters
target:target];
} else {
// Fallback on auto generated versions
return nil;
}
}
我不明白这是什么意思:
- 视图
- 窗户
在控制台的错误消息中。我应该在初始化 UITargetedDragPreview 之前将 previewView 添加到视图层次结构中吗?
谢谢!
【问题讨论】:
标签: ios xcode drag-and-drop ios13