UICollectionView-事件
2013-12-16 10:51
148 查看
1。UICollectionViewCell状态
highlighted:手指按下没抬起来
selected:手指按下,之后抬起来
selectedBackgroundView:选中背景
2。<UICollectionViewDelegate> 事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath //选中
collectionView:didDeselectItemAtIndexPath:
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath //高亮
collectionView:didUnhighlightItemAtIndexPath:
e.g.
const NSTimeInterval kAnimationDuration = 0.20; //作为后续的动画时间,如放大,缩小的动画持续时间
- (void) collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *selectedCell = [collectionView cellForItemAtIndexPath :indexPath];
[UIView animateWithDuration:kAnimationDuration animations:^{
selectedCell.transform = CGAffineTransformMakeScale(2.0f, 2.0f); //放大,参数:宽高缩放比例
}];
}
- (void) collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *selectedCell = [collectionView cellForItemAtIndexPath:indexPath];
[UIView animateWithDuration:kAnimationDuration animations:^{
selectedCell.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
}];
}
- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *selectedCell = [collectionView cellForItemAtIndexPath:indexPath];
//类似淡入淡出效果的动画效果, cell的awakeFromNib是在加载时会调用的初始化(在cell是xib文件时)
[UIView animateWithDuration:kAnimationDuration animations:^{
selectedCell.alpha = 0.0f; //透明
} completion:^(BOOL finished) {
[UIView animateWithDuration:kAnimationDuration animations:^{
selectedCell.alpha = 1.0f;
}];
}];
}
highlighted:手指按下没抬起来
selected:手指按下,之后抬起来
selectedBackgroundView:选中背景
2。<UICollectionViewDelegate> 事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath //选中
collectionView:didDeselectItemAtIndexPath:
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath //高亮
collectionView:didUnhighlightItemAtIndexPath:
e.g.
const NSTimeInterval kAnimationDuration = 0.20; //作为后续的动画时间,如放大,缩小的动画持续时间
- (void) collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *selectedCell = [collectionView cellForItemAtIndexPath :indexPath];
[UIView animateWithDuration:kAnimationDuration animations:^{
selectedCell.transform = CGAffineTransformMakeScale(2.0f, 2.0f); //放大,参数:宽高缩放比例
}];
}
- (void) collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *selectedCell = [collectionView cellForItemAtIndexPath:indexPath];
[UIView animateWithDuration:kAnimationDuration animations:^{
selectedCell.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
}];
}
- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *selectedCell = [collectionView cellForItemAtIndexPath:indexPath];
//类似淡入淡出效果的动画效果, cell的awakeFromNib是在加载时会调用的初始化(在cell是xib文件时)
[UIView animateWithDuration:kAnimationDuration animations:^{
selectedCell.alpha = 0.0f; //透明
} completion:^(BOOL finished) {
[UIView animateWithDuration:kAnimationDuration animations:^{
selectedCell.alpha = 1.0f;
}];
}];
}
相关文章推荐
- iOS UICollectionView 点击事件
- Swift UICollectionView、UITableView列点击事件与 UITapGestureRecognizer 点击事件冲突处理
- uicollectionView点击事件
- UIScrollView UICollectionView 无法响应touch事件
- 通过UICollectionView 自定义日历(Calendar)添加、编辑以及删除事件等操作
- UIImageView响应点击事件
- IOS开发:UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
- UIAlertView的基本使用和对话框中按钮的事件处理方法
- RecyclerView的点击事件和长按事件
- AndroidStudio GradView在RecyclerView中设置条目(Item)点击事件
- 给RecyclerView的item添加点击监听事件
- Android View的事件分发机制
- 事件处理:view 拖拽
- IOS 多个ImageView图片层叠透明区域点击事件穿透
- android中利用自定义View中的onTouchEvent捕捉长按事件
- android ViewPager实现无限轮播和设置监听事件
- iOS -实现imageView中的button响应点击事件的方法
- 自定义view随机数点击事件
- [iOS]技巧集锦:UICollectionView在旋转屏幕后Cell中的约束不起作用或自动布局失效
- RecycleView(BaseViewHolder+BaseAdapter+不同类型适配+点击事件)