我的应用中有一个DropAreaViewController
。在这个控制器里面我运行以下代码:
- (void)viewDidLoad {
[super viewDidLoad];
UIDropInteraction *interaction = [[UIDropInteraction alloc] initWithDelegate:self];
[self.view addInteraction:interaction];
}
- (BOOL)dropInteraction:(UIDropInteraction *)dropInteraction canHandleSession:(nonnull id<UIDropSession>)session {
NSLog(@"canHandleSession called");
return true;
}
- (UIDropProposal *)dropInteraction:(UIDropInteraction *)dropInteraction sessionDidUpdate:(nonnull id<UIDropSession>)session {
NSLog(@"sessionDidUpdate");
if (session.localDragSession != nil) {
NSLog(@"is localDragSession");
return [[UITableViewDropProposal alloc] initWithDropOperation:UIDropOperationMove intent:UITableViewDropIntentInsertAtDestinationIndexPath];
} else {
return [[UITableViewDropProposal alloc] initWithDropOperation:UIDropOperationCancel];
}
}
- (void)dropInteraction:(UIDropInteraction *)interaction performDrop:(id<UIDropSession>)session {
self.view.backgroundColor = [UIColor redColor];
}
现在,在另一个viewcontroller中我添加了这个控制器:
DropAreaViewController *davc = [[DropAreaViewController alloc] init];
davc.view.frame = CGRectMake(0, 0, 100, 100);
[self.view addSubview:davc.view];
虽然没有注册掉落。当我在广场上方悬停一滴时,我根本没有记录。有什么想法吗?