【发布时间】:2014-02-25 04:12:26
【问题描述】:
我有一个包含一些图像的集合视图。我还有另一个 UIView。我希望将集合视图中的图像拖放到 UIView 中,以便在 UIView 上放置一些动作时说颜色发生变化。此外,图像在放置后应保留在其原始位置。
这是我的集合视图代码。
-(UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell*aCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(3,5,100,100)];
imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.clipsToBounds = YES;
imgView.image = [UIImage imageNamed: [imagePackArray objectAtIndex:indexPath.row]];
[aCell addSubview:imgView];
aCell.backgroundColor = [UIColor redColor];
return aCell;
}
我尝试平移手势来实现这一点,但没有成功。
- (IBAction)handlePan:(UIPanGestureRecognizer *)sender {
NSLog(@"panning");
CGPoint translation = [sender translationInView:self.view];
sender.view.center = CGPointMake(sender.view.center.x + translation.x,
sender.view.center.y + translation.y);
[sender setTranslation:CGPointMake(0, 0) inView:self.view];
}
请看屏幕截图。我想将图像从集合视图拖到购物车图像(在 UIView 中)
我应该采取什么方法?有人可以指导我或提供可以提供帮助的代码 sn-ps/links 吗?
【问题讨论】:
-
你试过这个拖放吗? icodeblog.com/2008/10/20/…
-
或者也试试这个。 stackoverflow.com/a/16572995/2629258
-
是的。但我想从集合视图中添加拖拽。
标签: ios iphone drag-and-drop uicollectionview uigesturerecognizer