iOS7中奇怪的UITableViewCell选择 [英] Weird UITableViewCell selection in iOS7

查看:81
本文介绍了iOS7中奇怪的UITableViewCell选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 iOS7 中开发应用。我有一个 TableViewController ,它的样式被分组。
我成功实施了这个解决方案,可以获得曲线 TableView 我想要的。

I am developing an app in iOS7. I have one TableViewController, it's style is grouped. I successfully implemented this solution, can get curve to TableView as I want.

编辑: - 我没有为单元格使用任何自定义类。我刚刚从nib添加了 TableView ,并且默认使用了单元格。

- I am not using any custom class for cell. I have added TableView just from nib and also using by default cell.

实现的代码如下: -

Code implemented is as below :-

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(tintColor)]) {
        if (tableView == self.tblviwSample) {
            CGFloat cornerRadius = 5.f;
            cell.backgroundColor = UIColor.clearColor;
            CAShapeLayer *layer = [[CAShapeLayer alloc] init];
            CGMutablePathRef pathRef = CGPathCreateMutable();
            CGRect bounds = CGRectInset(cell.bounds, 10, 0);
            BOOL addLine = NO;
            if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
            } else if (indexPath.row == 0) {
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
                addLine = YES;
            } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
            } else {
                CGPathAddRect(pathRef, nil, bounds);
                addLine = YES;
            }
            layer.path = pathRef;
            CFRelease(pathRef);
            layer.fillColor = [UIColor colorWithWhite:1.f alpha:0.8f].CGColor;

            if (addLine == YES) {
                CALayer *lineLayer = [[CALayer alloc] init];
                CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
                lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+10, bounds.size.height-lineHeight, bounds.size.width-10, lineHeight);
                lineLayer.backgroundColor = tableView.separatorColor.CGColor;
                [layer addSublayer:lineLayer];
            }
            UIView *testView = [[UIView alloc] initWithFrame:bounds];
            [testView.layer insertSublayer:layer atIndex:0];
            testView.backgroundColor = UIColor.clearColor;
            cell.backgroundView = testView;
        }
    }
}

此代码的效果 - < a href =https://i.stack.imgur.com/rI9qa.png =nofollow noreferrer>在选择之前看到这个

Effect of this code - See this - before selection

但是遇到一个问题,当我选择一个单元格时,它看起来很奇怪,如这个

But getting one problem, when I select a cell, it's looking weird like this

我希望这个部分正确。任何想法都将不胜感激。

I want the section in proper manner. Any idea will be appreciated.

推荐答案

我会让桌面更薄(从两边减小宽度),然后实现你的外观该行不会在表视图的边缘之前结束,而是一直延伸到tableview的一侧。

I would make the tableview thinner (decrease width from both sides), then implement your looks so that the line would end not before edge of table view, but stretch all the way to the side of tableview.

换句话说 - 减少表视图宽度以匹配当前行宽度并将该行保留为现在的出价(然后它将与tableview一样宽)。您的选择现在也不会太宽。

In other words - decrease table view width to match current line width and leave the line as bid as it is now (it would then be as wide as tableview). Your selection will now be less wide too.

或者,在选择后,您可以修改表格视图单元格,以便模仿某些自定义选择。这可能是通过改变单元格颜色直到用动画来翻转它。

Or, upon selection you can modify your table view cell so that you mimic some custom selection. That could be from changing cell color up to flipping it with animations.

希望有所帮助。

这篇关于iOS7中奇怪的UITableViewCell选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆