UITableViewCell 撕裂的效果

来源:互联网 发布:phpstudy配置站点域名 编辑:程序博客网 时间:2024/04/26 23:44

总体思路就是: 点击cell时,重新加载tableView,在点击的行返回200的高度,本身cell为50px,

在tableView: cellForRowAtIndexPath:中对相应的行的(contentView中)加入一个高度为150px的UIView,

主要代码如下:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    if (self.selectIndex != nil && [self.selectIndex compare:indexPath] == NSOrderedSame)    {                return 200;    }    else    {        return 50;    }}- (UITableViewCell *)tableView:(UITableView *)tableView          cellForRowAtIndexPath:(NSIndexPath *)indexPath {        static NSString *UserLoginIdentifier = @"RecordManageCell";    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:                             UserLoginIdentifier];    if (cell == nil) {        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault                                       reuseIdentifier: UserLoginIdentifier] autorelease];            }    cell.selectionStyle = UITableViewCellSelectionStyleGray;    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//    NSInteger row = [indexPath row];    for (UIView *subView in cell.contentView.subviews)    {        if (subView.superview != nil)        {            [subView removeFromSuperview];        }    }    if (self.oldSelectIndex == self.selectIndex)    {            }    if (self.oldSelectIndex != NULL && self.oldSelectIndex != self.selectIndex)    {        UITableViewCell *cells = [tableView cellForRowAtIndexPath:self.oldSelectIndex];             for (UIView *subView in cells.contentView.subviews)        {            NSLog(@"%@",NSStringFromClass([subView class])) ;                        if (subView.superview != nil)            {                if ([NSStringFromClass([subView class]) isEqualToString:@"UIView"] )                {                     [subView removeFromSuperview];                }                           }        }    }        if (self.selectIndex != NULL && [self.selectIndex row] == [indexPath row])    {        UIView *subView = [[[UIView alloc] initWithFrame:CGRectMake(0, 50, 300, 150)] autorelease];        subView.backgroundColor = [UIColor blackColor];        [cell.contentView addSubview:subView];    }        CGSize size = cell.contentView.frame.size;        UILabel *lable = [[[UILabel alloc] initWithFrame:CGRectMake(10, 5, size.width, 35)] autorelease];        [cell.contentView addSubview:lable];        lable.backgroundColor = [UIColor clearColor];        lable.text = @"新民色fsf额s法";        return cell;}#pragma mark -#pragma mark Table Delegate Methods - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    //[tableView deselectRowAtIndexPath:indexPath animated:YES];    // [self playRecordFile:[indexPath row]];        self.oldSelectIndex = self.selectIndex;    self.selectIndex = indexPath;    NSArray *array = [NSArray arrayWithObject:indexPath];        [tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];}

效果如下: