簡體   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