【问题标题】:UICollectionView in view controller视图控制器中的 UICollectionView
【发布时间】:2014-03-21 06:43:26
【问题描述】:

我正在寻找将集合视图单元格中的图像拖放到同一视图控制器中但在集合视图之外的 UIImageView 的可能性。简历低于 5 个集合视图,我想将图像拖到集合视图中并将其放入集合视图上方的 5 个 UIImage 视图之一中。是否有可能从集合视图单元格中获取图像并以新顺序重新排列集合视图,以便在下面删除标记拖动的图像(和 cv-cell)?集合视图中的图像来自通过 json 加载的 url。我正在使用故事板和 ARC ... 非常感谢任何帮助或提示!

【问题讨论】:

    标签: objective-c drag-and-drop uicollectionview


    【解决方案1】:

    也许您可以在 NSMutableArray 中加载集合视图的图像,您可以运行该数组以获取集合视图必须显示的数据。当你将它从集合视图拖到 UIImageView 中时,删除 NSMutableArray 中该图像的对应索引并重新加载集合视图数据。同时,您获取该图像数据并将其加载到图像视图。如果我了解您的问题,这可能会有所帮助。

    【讨论】:

    • 谢谢。我现在将图像从数据库加载到数组中。我实际上在实现我的 dragEnded 方法时遇到了问题。我必须为视图控制器分类一个类,为 collevtionviewcell 分类一个类,并且每个类中有 2 个拖放方法。目前我的uiimageview没有得到我在集合视图中拖动的图像......认为类不对应......参数保持为空......嗯......
    • - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {if ([touches count] == 1) { CGPoint touchPoint = [[touches anyObject] locationInView:self. superview.superview]; for (UIImageView *iView in self.subviews) { if ([iView isMemberOfClass:[UIImageView class]]) {if (touchPoint.x > iView.frame.origin.x && touchPoint.x iView.frame.origin.y && touchPoint.y
    • touchPoint.y - iView.frame.origin.y); self.homePosition = CGPointMake(iView.frame.origin.x, iView.frame.origin.y);}}}}}
    • - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint touchPoint = [[touches anyObject] locationInView:self.superview]; CGRect newDragObjectFrame = CGRectMake(touchPoint.x - _touchOffset.x, touchPoint.y - _touchOffset.y, self.frame.size.width, self.frame.size.height); self.frame = newDragObjectFrame; [self.superview.superview bringSubviewToFront:self]; }
    • - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { FirstViewController *fvc = [FirstViewController new]; CGPoint touchPoint = [[touches anyObject] locationInView:self.superview.superview]; fvc.mainImageview.image = self.dragObject.image; NSLog(@"mainImageviewimage%@",fvc.mainImageview.image); }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多