UICollectionViewCell子视图接收点击insted

时间:2012-12-27 17:53:03

标签: ios uiview uicollectionviewcell

我有一个UICollectionViewCell,其中包含我的一些内容,如图片,标签,视图。

我想获得这种行为(就像正常细胞的相反行为):

  • 默认情况下,此单元格有一个视图(一个简单的UIView,其alpha设置显示一些不透明度),就像没有选择它一样。
  • 当用户选择单元格时,必须删除此Alpha视图。

如果我尝试安装UITapRecognizer:

    // Create gesture recognizer
UITapGestureRecognizer *oneTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onShadowLayerPressed)];

// Set required taps and number of touches
[oneTap setNumberOfTapsRequired:1];
[oneTap setNumberOfTouchesRequired:1];

// Add the gesture to the view
[self.shadowView addGestureRecognizer:oneTap];

并在方法之后

 - (void)onShadowLayerPressed
{
    [super setSelected:YES];
    [self setSelected:YES];
}

从self.shadowView收到tap,但它不会发送到单元格....

我该如何解决这个问题?

由于

1 个答案:

答案 0 :(得分:1)

您正在使用@property (nonatomic, getter=isSelected) BOOL selected并根据docs

  

您通常不直接设置此属性的值。以编程方式更改此属性的值不会更改单元格的外观。选择单元格并突出显示它的首选方法是使用集合视图对象的选择方法。

所以你应该使用:

- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition

记录在案here

相关问题