您的位置:首页 > 产品设计 > UI/UE

[iOS]点击UITableView的Cell紧随其后出现一行功能栏

2014-03-26 00:28 483 查看
[iOS]点击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


效果图:

 


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐