繁体   English   中英

CoreGraphics无法在iOS 7.0模拟器上运行

[英]CoreGraphics not working on iOS 7.0 simulator

自iOS 7 Alpha以来,我一直在为此苦苦挣扎。 首先,我认为这是Alpha上的错误,但仍在发生,所以我做错了什么。

在整个应用程序中,我正在绘制诸如单元格背景之类的东西,以及CG之类的东西,但是在iOS 7中却不显示。

举个例子:

@interface NewManagerCell : UITableViewCell
@end

@implementation NewManagerCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //some initialization code here
    }
    return self;
}
- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGRect bounds = self.bounds;
    bounds.origin.y += 5; //inter-cell spacing
    bounds.size.height -= 5;

    CGFloat mx = CGRectGetMinX(bounds);
    CGFloat Mx = CGRectGetMaxX(bounds);
    CGFloat my = CGRectGetMinY(bounds);
    CGFloat cy = CGRectGetMinY(bounds)+CGRectGetHeight(bounds)*.375;
    CGFloat My = CGRectGetMaxY(bounds);

    CGContextBeginPath(context);

    CGContextMoveToPoint(context, mx, cy);
    CGContextAddLineToPoint(context, mx+cy-my, my);
    CGContextAddLineToPoint(context, Mx-cy+my, my);
    CGContextAddLineToPoint(context, Mx, cy);
    CGContextAddLineToPoint(context, Mx, My);
    CGContextAddLineToPoint(context, mx, My);
    CGContextAddLineToPoint(context, mx, cy);

    CGContextSetFillColorWithColor(context, [[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell-pattern"]] CGColor]);
    CGContextFillPath(context);

    mx += 4+CGRectGetWidth(bounds)/4-CGRectGetHeight(bounds)*.375/16;
    Mx -= 4;
    my += 4;
    My -= 4;
    cy += 2;

    CGMutablePathRef path = CGPathCreateMutable();

    CGContextBeginPath(context);

    CGPathMoveToPoint(path, &CGAffineTransformIdentity, mx, my);
    CGPathAddLineToPoint(path, &CGAffineTransformIdentity, Mx-(cy-my), my);
    CGPathAddLineToPoint(path, &CGAffineTransformIdentity, Mx, cy);
    CGPathAddLineToPoint(path, &CGAffineTransformIdentity, Mx, My);
    CGPathAddLineToPoint(path, &CGAffineTransformIdentity, mx, My);
    CGPathAddLineToPoint(path, &CGAffineTransformIdentity, mx, my);

    CGContextAddPath(context, path);
    CGContextSetRGBFillColor(context, 1, 1, 1, 1);
    CGContextFillPath(context);

    CGContextAddPath(context, path);
    CGContextSetRGBStrokeColor(context, .69, .69, .69, 1);
    CGContextStrokePath(context);

    CGPathRelease(path);
}
@end

在7之前的任何版本的iOS中都可以使用,但现在停止了工作。 有人对发生的事情有任何线索吗?

尝试创建一个自定义UIView ,其中包含要绘制的代码,然后可以将SubView添加到单元格的根视图中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM