iphone-67-长按uitableview的row,实现reorder
来源:互联网 发布:java jdbc连接池使用 编辑:程序博客网 时间:2024/06/06 11:02
iphone-67-长按uitableview的row,实现reorder
(2012-06-11 15:10:26)iphone
reorder
cell
uitableview
长按
隐藏
it
分类: iPhoneA component of one of our upcoming apps is a Scramble type game where letters are rearranged to solve the word. I had a fantastic idea to use a
Open the project startpoint
NSLog(@"%@", cell.subviews);
Run the project and you will see a view called “UITableViewCellReorderCo
Because we dont have the class definition for “UITableViewCellReorderCo
for(UIView* view in cell.subviews){ if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl" ]) { NSLog(@"%@", view); [view setBackgroundColor:[UIColor redColor]]; }}
Run the project, only the “UITableViewCellReorderCo
You can try setting the frame of this view, but the
for(UIView* view in cell.subviews){ if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl" ]) { [view setBackgroundColor:[UIColor redColor]]; UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))]; [resizedGripView setBackgroundColor:[UIColor greenColor]]; [resizedGripView addSubview:view]; [cell addSubview:resizedGripView]; [resizedGripView release]; }}
Run the app and now all cell’s are filled with our custom green view with the red grip on the right. Reordering functionality will still work. Now it’s time to figure our what transform this custom view requires for it to fill the entire cell.
for(UIView* view in cell.subviews){ if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl" ]) { [view setBackgroundColor:[UIColor redColor]]; UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))]; [resizedGripView setBackgroundColor:[UIColor greenColor]]; [resizedGripView addSubview:view]; [cell addSubview:resizedGripView]; [resizedGripView release]; CGSize sizeDifference = CGSizeMake(resizedGripView.frame.size.width - view.frame.size.width, resizedGripView.frame.size.height - view.frame.size.height); CGSize transformRatio = CGSizeMake(resizedGripView.frame.size.width / view.frame.size.width, resizedGripView.frame.size.height / view.frame.size.height); // Original transform CGAffineTransform transform = CGAffineTransformIdentity; // Scale custom view so grip will fill entire cell transform = CGAffineTransformScale(transform, transformRatio.width, transformRatio.height); // Move custom view so the grip's top left aligns with the cell's top left transform = CGAffineTransformTranslate(transform, -sizeDifference.width / 2.0, -sizeDifference.height / 2.0); [resizedGripView setTransform:transform]; }}
This will make the grip take up the entire cell, you can now reorder from any point on the cell, perfect. Now just some cleanup, remove the red and green colours from the custom view and the “UITableViewCellReorderCo
for(UIImageView* cellGrip in view.subviews){ if([cellGrip isKindOfClass:[UIImageView class]]) [cellGrip setImage:nil];}
And that is all that’s required, not too much code at all, just a bit of subview hunting and testing to see what works. Here is the complete
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ // Grip customization code goes in here... for(UIView* view in cell.subviews) { if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl" ]) { UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))]; [resizedGripView addSubview:view]; [cell addSubview:resizedGripView]; [resizedGripView release]; CGSize sizeDifference = CGSizeMake(resizedGripView.frame.size.width - view.frame.size.width, resizedGripView.frame.size.height - view.frame.size.height); CGSize transformRatio = CGSizeMake(resizedGripView.frame.size.width / view.frame.size.width, resizedGripView.frame.size.height / view.frame.size.height); // Original transform CGAffineTransform transform = CGAffineTransformIdentity; // Scale custom view so grip will fill entire cell transform = CGAffineTransformScale(transform, transformRatio.width, transformRatio.height); // Move custom view so the grip's top left aligns with the cell's top left transform = CGAffineTransformTranslate(transform, -sizeDifference.width / 2.0, -sizeDifference.height / 2.0); [resizedGripView setTransform:transform]; for(UIImageView* cellGrip in view.subviews) { if([cellGrip isKindOfClass:[UIImageView class]]) [cellGrip setImage:nil]; } } }}
And here is the project endpoint.- iphone-67-长按uitableview的row,实现reorder
- UITableView 的长按事件
- UITableView刷新指定的row或者section
- UITableView获取cell的row值
- UITableView长按手势UILongPressGestureRecognizer
- UITableView长按手势UILongPressGestureRecognizer
- iPhone UITableView(利用UITableView实现平滑的九宫格效果)
- iPhone UITableView(利用UITableView实现平滑的九宫格效果)
- iphone--UITableView的Edit方法
- iPhone:UITableVIew 的一些理解
- 在对UITableView添加长按事件的时候,有的列表不响应长按
- iphone uitable+长按事件
- iPhone UITableView
- 获取UItableView中button所在的section和row
- UITableView获取cell的indexPath.row值(多种方式)
- UITableView使用方法(二) - 增加长按事件
- UITableView 添加长按手势UILongPressGestureRecognizer
- iOS UITableView(八) cell长按快捷键
- Android—去掉ExpandableListView的箭头图标
- Android学习笔记——ListView
- JVM总结
- Nginx Location配置总结
- Android调用系统相机拍照,并且模仿实现水印相机简单功能
- iphone-67-长按uitableview的row,实现reorder
- JS获取表单元素的value
- Linux NFS服务器的安装与配置
- 欢迎使用CSDN-markdown编辑器
- 魅族手机无法连接到MAC使用abd
- 城域网IPv6过渡技术―DS-lite的业务流程
- ExtJS加载iframe后回调的另一个思路
- Linux下helloworld的简单编译过程
- jquery选中表格的某行变色