[iOS]点击UITableView的Cell紧随其后出现一行功能栏
2014-03-26 00:28
483 查看
[iOS]点击UITableView的Cell紧随其后出现一行功能栏
长按UITableView的Cell,紧跟着弹出一行功能栏
补充:另外一种解决方式参见文章:http://blog.csdn.net/wsyx768/article/details/20490843
UITableView声明部分:
自定义Cell部分:
效果图:
长按UITableView的Cell,紧跟着弹出一行功能栏
补充:另外一种解决方式参见文章:http://blog.csdn.net/wsyx768/article/details/20490843
UITableView声明部分:
#import <UIKit/UIKit.h> #import "WASongMenuCell.h"//自定义Cell @interface WASongMenu : UIViewController<UITableViewDataSource,UITableViewDelegate> @property (strong, nonatomic) NSMutableArray *wSongSectionArr; //歌单组数 @property (strong, nonatomic) UITableView *wSongDataTV; //歌单内容承载TableView @property (strong, nonatomic) NSMutableArray *wJudgeSectionRow;//判断选择歌单 @property (strong, nonatomic) UIView *wFunctionV; //点击Cell,弹出功能框 @end - (WASongMenuCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell"; WASongMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //关键的一步,每次赋值时先清空cell cell = nil; if (cell == nil) { cell = [[WASongMenuCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } [cell setBackgroundColor:[UIColor clearColor]]; if(indexPath.row == 0){ [cell mSongMenuListTitle:strKey andHeight:60]; //添加手势 UILongPressGestureRecognizer *titleLPGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(mTitleLongPress:)]; //几个手指按屏幕 [titleLPGR setNumberOfTouchesRequired:1]; //最大100像素的移动是手势识别所允许的 [titleLPGR setAllowableMovement:100]; //两次点击之间的时间长度 [titleLPGR setMinimumPressDuration:1]; [cell addGestureRecognizer:titleLPGR]; }else{ if([ValueArr count]){ [cell mSongMenuPhoto:Nil andSinger:[ValueArr objectAtIndex:indexPath.row-1] andSongName:nil andHeight:60]; //添加手势 UILongPressGestureRecognizer *songLPGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(mSongLongPress:)]; [songLPGR setNumberOfTouchesRequired:1]; [songLPGR setAllowableMovement:100]; [songLPGR setMinimumPressDuration:1]; [cell addGestureRecognizer:songLPGR]; } } return cell; } //长按歌单 -(void)mTitleLongPress:(id)recognizer{ UILongPressGestureRecognizer *tempLP = (UILongPressGestureRecognizer *)recognizer; [self.wFunctionV setFrame:CGRectMake(self.wFunctionV.frame.origin.x, self.wFunctionV.frame.origin.y, 320, 60)]; self.wFunctionV = tempLP.view; [self.wFunctionV setFrame:CGRectMake(self.wFunctionV.frame.origin.x, self.wFunctionV.frame.origin.y, 320, 120)]; NSLog(@"歌单"); } //长按歌曲 -(void)mSongLongPress:(id)recognizer{ UILongPressGestureRecognizer *tempLP = (UILongPressGestureRecognizer *)recognizer; [self.wFunctionV setFrame:CGRectMake(self.wFunctionV.frame.origin.x, self.wFunctionV.frame.origin.y, 320, 60)]; self.wFunctionV = tempLP.view; [self.wFunctionV setFrame:CGRectMake(self.wFunctionV.frame.origin.x, self.wFunctionV.frame.origin.y, 320, 120)]; NSLog(@"歌曲"); }
自定义Cell部分:
#import <UIKit/UIKit.h> @interface WASongMenuCell : UITableViewCell //列表Cell -(void)mSongMenuListTitle:(NSString *)title andHeight:(float)height; //歌曲Cell -(void)mSongMenuPhoto:(UIImage *)photo andSinger:(NSString *)singer andSongName:(NSString *)song andHeight:(float)height; @end #import "WASongMenuCell.h" @implementation WASongMenuCell //列表Cell -(void)mSongMenuListTitle:(NSString *)title andHeight:(float)height{ UILabel *titleLab = [[UILabel alloc] init]; [titleLab setFrame:CGRectMake(5, 5, 310, height-10)]; [self.contentView addSubview:titleLab]; [titleLab setText:title]; //Cell下方隐藏功能部分 UIView *downV = [[UIView alloc] initWithFrame:CGRectMake(0, height, 320, height)]; [self.contentView addSubview:downV]; //四个功能Button NSArray *tempArr = [[NSArray alloc] initWithObjects:@"稍后播放",@"重命名",@"删除", nil]; for(int i = 0;i < 3;i ++){ UIButton *tempBut = [[UIButton alloc] initWithFrame:CGRectMake(i*(320/3), height, 320/3-1, height)]; [tempBut setTitleColor:[WASharedFontStyle mGetSharedFontColor] forState:UIControlStateNormal]; [tempBut setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [tempBut setTitle:[tempArr objectAtIndex:i] forState:UIControlStateNormal]; [self.contentView addSubview:tempBut]; if(i<2){ UIView *tempV = [[UIView alloc] initWithFrame:CGRectMake(320/3+i*(320/3), height+(height-height*2/3)/2, 1, height*2/3)]; [self.contentView addSubview:tempV]; } } } //歌曲Cell -(void)mSongMenuPhoto:(UIImage *)photo andSinger:(NSString *)singer andSongName:(NSString *)song andHeight:(float)height{ //头像 UIImageView *tempIV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, height-10, height-10)]; [self.contentView addSubview:tempIV]; [tempIV setImage:photo]; [tempIV setBackgroundColor:[UIColor blueColor]]; //歌手 UILabel *singerLab = [[UILabel alloc] initWithFrame:CGRectMake(height, 5, 320-height-10, height-10)]; [singerLab setNumberOfLines:2]; [singerLab setFont:[UIFont systemFontOfSize:18]]; [self.contentView addSubview:singerLab]; [singerLab setText:@"暂无歌手信息"]; //歌曲名 NSString *tempInfo = [NSString stringWithFormat:@"%@-%@",singer,song]; if(tempInfo){ [singerLab setText:tempInfo]; } //Cell下方隐藏功能部分 UIView *downV = [[UIView alloc] initWithFrame:CGRectMake(0, height, 320, height)]; [self.contentView addSubview:downV]; //四个功能Button NSArray *tempArr = [[NSArray alloc] initWithObjects:@"下载",@"添加",@"分享",@"歌曲信息", nil]; for(int i = 0;i < 4;i ++){ UIButton *tempBut = [[UIButton alloc] initWithFrame:CGRectMake(i*(320/4), height, 320/4-1, height)]; [tempBut setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [tempBut setTitle:[tempArr objectAtIndex:i] forState:UIControlStateNormal]; [self.contentView addSubview:tempBut]; if(i<3){ UIView *tempV = [[UIView alloc] initWithFrame:CGRectMake(320/4+i*(320/4), height+(height-height*2/3)/2, 1, height*2/3)]; [tempV setBackgroundColor:[WASharedFontStyle mGetSharedFontColor]]; [self.contentView addSubview:tempV]; } } } @end
效果图:
相关文章推荐
- 如何通过代理之道UItableView上cell上面的button点击的是哪一行的
- iOS关闭UITableView中cell的点击事件
- IOS UITableViewUITableView小技巧--实现cell向左滑动删除,编辑等功能
- iOS中UITableView的cell点击事件不触发didSelectRowAtIndexPath
- ios UITableView 获取点击cell对象
- iOS中UITableView的cell点击事件不触发didSelectRowAtIndexPath
- iOS - UITableView中的cell因为重用机制导致新的cell的数据出现重复或者错乱
- iOS开发中实现UITableView的Cell左划删除等自定义功能
- Ios 该图显示其出现的相关问题定义UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
- iOS开发-UI控件:让UITableView自动滑动(定位)到某一行cell
- iOS UITableView中关于cell里的按钮被点击时如何确定是哪一个section
- iOS项目开发小技巧 (三) --UITableView实现Cell左划删除等自定义功能
- Ios 自定义表示图出现的相关问题UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
- iOS UITableView中关于cell里的按钮被点击时如何确定是哪一个section
- iOS点击UITableView的cell,弹出UIAlertController有时会出现延迟
- iOS App中UITableView左滑出现删除按钮及其cell的重用
- 【iOS】UITableView Cell自定义单选功能
- iOS开发:UITableView实现侧滑删除cell的功能
- iOS UITableView中关于cell里的按钮被点击时如何确定是哪一个section
- iOS中UITableView Cell实现自定义单选功能