标签: uicollectionviewcell

在UICollectionView中复制标注

我在每个单元格中都有一个带UIImageView的UICollectionView,现在我想添加Copy Callout,就像在Photos.app中一样:

在此输入图像描述

我在UICollectionViewDelegate中看到了这个方法:

- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

经过几分钟的研究后,我找到了UIMenuController类,据我所知,我必须使用它来获取菜单,但无论如何,我认为必须有更简单的方法然后创建UIGestureRecognizer,创建,定位等我的UIMenu.

我是在正确的轨道上吗?你怎么能实现这个功能?

ios ios5 ios6 uicollectionview uicollectionviewcell

8
推荐指数
3
解决办法
7928
查看次数

根据UICollectionView中的图像动态更改单元格大小

我正在水平集合视图中显示从服务器收到的动态图像.当我设置集合视图时,我设置了这个:

-(void)setupCollectionView{
[self setupPageControlView];
self.screensCollectionView.delegate=self;
self.screensCollectionView.dataSource=self;
[self.screensCollectionView registerNib:[UINib nibWithNibName:@"FGAppScreensCollectionViewItemCell" bundle:nil] forCellWithReuseIdentifier:@"screenCell"];


UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[flowLayout setMinimumInteritemSpacing:0.0f];
[flowLayout setMinimumLineSpacing:0.0f];
[flowLayout setItemSize:CGSizeMake(165, 255)];
//[self.screensCollectionView setPagingEnabled:YES];
[self.screensCollectionView setCollectionViewLayout:flowLayout];
Run Code Online (Sandbox Code Playgroud)

}

对于cellForRowAtIndexPath我下载这样的图像:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"screenCell";

FGAppScreensCollectionViewItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[self.imageURLArray objectAtIndex:indexPath.row]]];

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[spinner startAnimating];
[spinner setFrame:CGRectMake(50, 100, 20, 20)];
[cell.contentView addSubview:spinner];
[cell.screenImageView setImageWithURLRequest:urlRequest placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview uicollectionviewcell uicollectionviewlayout

8
推荐指数
2
解决办法
2万
查看次数

UICollectionViewCell自动布局

UICollectionViewCell在故事板中编写了一个简单的自定义,我也以编程方式完成了相同的结果.

它有一个单数UIImageView和两个UILabels,如下:

          <--UIIMAGEVIEW-->          <--UILABEL-------->
|-(10px)- |               | -(10px)-                     -(10px)-|
          <--------------->          <--UILABEL-------->
Run Code Online (Sandbox Code Playgroud)

图像位于左侧,然后右侧是两个上下标签.

每个间隔有10个像素间隙,并且全部以单元Y轴为中心.然后标签有一个常数来偏离中心(向上和向下).

图像的高度和宽度固定为44px,标签的固定高度为20px(宽度灵活).

约束按预期工作,永远不会破坏应用程序,但它们总是在下面吐出这个恼人的控制台日志信息,因为它们显然正在破坏.

如果我将此行添加到我的UICollectionViewCell子类中,则约束不再中断并吐出控制台错误,但它们在屏幕上完全被破坏.

[self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
Run Code Online (Sandbox Code Playgroud)

有线索吗?这看起来很不合逻辑!

这是控制台错误代码:

2014-10-25 18:28:14.273 Air Plan[1579:580797] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ios autolayout uicollectionviewcell

8
推荐指数
1
解决办法
7963
查看次数

为集合视图单元格设置自动布局宽度和高度约束的最佳做法?

我正在设计一个快速构建的ios 8应用程序的UI.我对autolayout和约束有中级知识.这是我的情况:我有一个自定义集合视图控制器和集合视图单元格.我想在界面构建器中使用"等宽"和"相等高度"约束来设置单元格的宽度和高度相对于父视图的乘数 - 而不是使用固有的高度/宽度属性,如320 x 94.

这是我尝试过的

  1. 使用IB内部大小类的固有宽度和高度.(这不起作用)
  2. 控制 - 从UICollectionViewCell拖动到CollectionView(看不到"相等高度"和"相等宽度"甚至不是约束选项)

我应该只考虑内在的高度和宽度,并假设CollectionViewFlowLayout将照顾我或有没有办法以编程方式执行此操作?

谢谢.亚历克斯

ios autolayout uicollectionview uicollectionviewcell swift

8
推荐指数
1
解决办法
2244
查看次数

UICollectionViewCell和UICollectionReusableView有什么区别?

通过UICollectionView教程,我看到一些UICollectionViewCell子项在哪里UICollectionReusableView被子类化,而另一些在哪里被子类化.当你使用一个而不是另一个时,文档并没有说清楚.

ios uicollectionview uicollectionviewcell swift

8
推荐指数
1
解决办法
3185
查看次数

UICollectionView重复单元格

我有一个UICollectionView显示从Internet下载的图像网格的地方.我正在使用SDWebImage加载图像.我面临的问题是,当我滚动浏览时UICollectionView,有时单元格会重复,显示相同的图像.但是当单元格滚出视图然后返回时,它具有正确的图像集.

-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    NSString *CellIdentifier = @"Gallery_Cell";

    GalleryCell *cell;

    if (cell==nil) {
        cell= (GalleryCell *)[self.flowCollection dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

        ImageItem *dets = [self.imageList objectAtIndex:indexPath.row];

        NSURL *mainImageURL = [NSURL URLWithString:dets.smallImageURL];

        cell.image.contentMode = UIViewContentModeScaleAspectFill;
        cell.image.clipsToBounds = YES;                

        [cell.image setImageWithURL:mainImageURL placeholderImage:nil];

    }

    return cell;

}
Run Code Online (Sandbox Code Playgroud)

这有发生在其他人身上吗?非常感谢任何指针.

iphone ios uicollectionview uicollectionviewcell

7
推荐指数
3
解决办法
6599
查看次数

UICollectionView分页偏移和间距

我很难过.我有这个集合视图显示单元格的边缘作为滑动可用的提示,但只有第一个和最后一个单元格正确显示.介于两者之间的一切都没有正确排队.我错过了什么?

UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(280, 400);
layout.sectionInset = UIEdgeInsetsMake(0, 20, 0, 20);
layout.minimumInteritemSpacing = 10;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumLineSpacing = 10.0;

self.collectionView.collectionViewLayout = layout;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.pagingEnabled = YES;
self.collectionView.clipsToBounds = NO;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

ios uicollectionview uicollectionviewcell uicollectionviewlayout

7
推荐指数
1
解决办法
5133
查看次数

使用Swift的UICollectionView错误

我收到此错误,尝试在Swift中使用UICollectionView:

NSInternalInconsistencyException', reason: 'attempt to register a cell class which is not a subclass of UICollectionViewCell ((null))
Run Code Online (Sandbox Code Playgroud)

但我想我正在注册这个单元格:

  1. viewDidLoad中:

    override func viewDidLoad()
    {
        super.viewDidLoad()
        self.collectionView.registerClass(NSClassFromString("CollectionCell"),forCellWithReuseIdentifier:"CELL")
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. cellForItemAtIndexPath:

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath:NSIndexPath)->UICollectionViewCell
    {
       var  cell = collectionView.dequeueReusableCellWithReuseIdentifier("CELL", forIndexPath: indexPath) as CollectionCell
    
        cell.titleLabel.text="cellText"
        return cell
    }
    
    Run Code Online (Sandbox Code Playgroud)

和细胞类:

    class CollectionCell: UICollectionViewCell
    {

        @IBOutlet var titleLabel : UILabel
        init(coder aDecoder: NSCoder!)
        {
            super.init(coder: aDecoder)

        } 
     }
Run Code Online (Sandbox Code Playgroud)

任何帮助赞赏

objective-c ios uicollectionview uicollectionviewcell swift

7
推荐指数
1
解决办法
1万
查看次数

带标题的两列UICollectionView

我的布局有两列并排.使用单个UICollectionView有一种简单的方法吗?唯一的要求是该解决方案必须适用于iOS 8,并且单元格必须在每列中垂直堆叠,如下所示:

   -----------------
   |       A       |
   |       B       |
   -----------------
   |   C   |   E   |
   |   C   |   F   |
   |   D   |       |
   |   E   |       |
   -----------------
Run Code Online (Sandbox Code Playgroud)

堆叠的Cs表明左右列中的单元格可以是不同的高度,因此仅仅左,右,左,右绘制它们是不够的.

uicollectionview uicollectionviewcell uicollectionviewlayout uicollectionreusableview

7
推荐指数
1
解决办法
696
查看次数

如何在didSelect上添加边框到UICollectionViewCell并在选择另一个UICollectionViewCell时删除该边框?

例如,我有10个单元格的UICollectionView.我想为选定的单元格添加边框,稍后,在选择另一个单元格时,要删除以前的边框并为新选定的单元格添加边框.

我怎样才能做到这一点?

我试过这个:

var selected = [NSIndexPath]()
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    self.imageView.image = applyFilter(self.colorCubeFilterFromLUT("\(self.LUTs[indexPath.row])")!, image: self.image!)

    self.selected.append(indexPath)
}

func collectionView(collectionView: UICollectionView, didHighlightItemAtIndexPath indexPath: NSIndexPath) {
    let cell = self.filtersCollectionView.cellForItemAtIndexPath(indexPath) as! FiltersCollectionViewCell
    cell.imageView.layer.borderWidth = 3.0
    cell.imageView.layer.borderColor = UIColor.brownColor().CGColor
}

func collectionView(collectionView: UICollectionView, didUnhighlightItemAtIndexPath indexPath: NSIndexPath) {

    if self.selected.count > 1 && indexPath == self.selected[self.selected.count - 1] {            
        let cell = self.filtersCollectionView.cellForItemAtIndexPath(indexPath) as! FiltersCollectionViewCell
        cell.imageView.layer.borderWidth = 0.0
        cell.imageView.layer.borderColor = UIColor.clearColor().CGColor
    }
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我做错了什么?

ios uicollectionview uicollectionviewcell swift

7
推荐指数
2
解决办法
7962
查看次数