AQGridView开源库中的示例DEMO:SpringBoard中为什么需要empty cell
来源:互联网 发布:软件项目管理软件书籍 编辑:程序博客网 时间:2024/05/21 05:20
这几天在看AQGridView开源库中的示例DEMO:SpringBoard,一直不明白里面为什么会有empty cell,看了几遍代码终于明白了。
先看下面的代码:
case UIGestureRecognizerStateBegan: { NSLog(@"UIGestureRecognizerStateBegan"); NSUInteger index = [_gridView indexForItemAtPoint: [recognizer locationInView: _gridView]]; _emptyCellIndex = index; // we'll put an empty cell here now // find the cell at the current point and copy it into our main view, applying some transforms AQGridViewCell * sourceCell = [_gridView cellForItemAtIndex: index]; CGRect frame = [self.view convertRect: sourceCell.frame fromView: _gridView]; _draggingCell = [[SpringBoardIconCell alloc] initWithFrame: frame reuseIdentifier: @""]; _draggingCell.icon = [_icons objectAtIndex: index]; [self.view addSubview: _draggingCell]; // grab some info about the origin of this cell _dragOriginCellOrigin = frame.origin; _dragOriginIndex = index; [UIView beginAnimations: @"" context: NULL]; [UIView setAnimationDuration: 0.2]; [UIView setAnimationCurve: UIViewAnimationCurveEaseOut]; // transformation-- larger, slightly transparent --> 按住后,原来的图标变大和透明 by jfl _draggingCell.transform = CGAffineTransformMakeScale( 1.2, 1.2 ); _draggingCell.alpha = 0.7; // also make it center on the touch point _draggingCell.center = [recognizer locationInView: self.view]; [UIView commitAnimations]; // reload the grid underneath to get the empty cell in place |--> 加载放大之后,下面的那个empty cell的,如果注释掉这段代码,变化之前的icon还在原地 by jfl NSLog(@"**********");// [_gridView reloadItemsAtIndices: [NSIndexSet indexSetWithIndex: index]// withAnimation: AQGridViewItemAnimationNone]; NSLog(@"----------"); break; }
如果我们把
// [_gridView reloadItemsAtIndices: [NSIndexSet indexSetWithIndex: index]// withAnimation: AQGridViewItemAnimationNone];
注释掉。运行程序会发现如下效果:
在我们拖动的过程当中,左边原来的图标会一直显示,这显然是不对的。
如果不注释掉那个代码它就会调用下面的方法:
- (AQGridViewCell *) gridView: (AQGridView *) gridView cellForItemAtIndex: (NSUInteger) index{ NSLog(@"gridView cellForItemAtIndex"); static NSString * EmptyIdentifier = @"EmptyIdentifier"; static NSString * CellIdentifier = @"CellIdentifier"; if ( index == _emptyCellIndex ) { NSLog( @"Loading empty cell at index %u", index ); AQGridViewCell * hiddenCell = [gridView dequeueReusableCellWithIdentifier: EmptyIdentifier]; if ( hiddenCell == nil ) { // must be the SAME SIZE AS THE OTHERS // Yes, this is probably a bug. Sigh. Look at -[AQGridView fixCellsFromAnimation] to fix hiddenCell = [[AQGridViewCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 72.0, 72.0) reuseIdentifier: EmptyIdentifier]; }// 如果把这行代码注释掉,icon下面会出现个白色的矩形,所以才用EmptyIdentifier | by jfl// hiddenCell.hidden = YES; return ( hiddenCell ); } SpringBoardIconCell * cell = (SpringBoardIconCell *)[gridView dequeueReusableCellWithIdentifier: CellIdentifier]; if ( cell == nil ) { cell = [[SpringBoardIconCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 72.0, 72.0) reuseIdentifier: CellIdentifier]; } cell.icon = [_icons objectAtIndex: index]; return ( cell );}此时,index == _emptyCellIndex,它会返回那个hiddenCell,即empty cell。然后把它隐藏,这样,我们在拖动的过程当中就看不到它了,达到了要实现的效果。
如果我们把
// hiddenCell.hidden = YES;
注释掉,可以看到下面的效果:
这其实就是拖动过程当中一直有这个empty cell,只不过被隐藏了。这样就达到了拖动的效果。
- AQGridView开源库中的示例DEMO:SpringBoard中为什么需要empty cell
- Springboard
- 浅析Fragment为什么需要Public的empty constructor
- excel auto delete empty cell
- java中为什么需要接口
- Android中为什么需要服务?
- css中为什么需要浮动?
- java中为什么需要多线程
- 开发中为什么需要多线程?
- iOS:一个Cell中设置另外一个Cell中的button
- ios 自定义cell demo
- ffmpeg 中hello-jni demo 示例
- boost中的ordered_free为什么需要做排序
- 为什么需要Spring?--Spring中的设计模式
- C++中的为什么需要虚析构函数
- tableview中需要header随着cell一起滚动
- Gridview cell text values all Empty Strings
- PHP中empty,is_null,isset,array() 中的异同和功能
- 程序跳转
- 【Java常用类库】_Runtime类
- SD卡SPI模式下FatFs与znFat文件系统速度比较
- configure -h 参数详解
- HANA简介
- AQGridView开源库中的示例DEMO:SpringBoard中为什么需要empty cell
- Gabor变换
- Windows CE 模拟器和远程调试工具
- ENVI下DOM数据生产专题之图像增强
- xcode 4.5.2 中使用 ios 6 skd iOS/Xcode异常:reason: ‘Could not instantiate class named NSLayoutConstraint’
- 使用CoreData的轻量级自动数据迁移
- 回顾我的2012
- 动态MBean
- Mina学习笔记(4)IoService