2

この形状のようなものを再作成しようとしています - http://www.creativeapplications.net/wp-content/uploads/2010/09/horizo ​​n_02_1024x768.png - iOS で UIKit または CoreGraphics を使用します。

写真のものはopenFrameworksで行われ、iOSで動作します。ただし、oF を使用せずに同じものをビルドしたいので、すべてネイティブのままにしておくことができます。

形状は Delaunay 三角形分割によって作成されたと思いますが、これは Objective-C で行うことができます。問題は、通常の UIColor ではなくグラデーションでシェイプを塗りつぶすことです!

このようなことをiPad で優れたパフォーマンスでネイティブに実行できる方法はありますか、それとも openFrameworks でそれを実行し、それをレイヤーとしてアプリに取り込む必要がありますか?

4

2 に答える 2

2

三角形をグラデーションで塗りつぶす方法を尋ねていますか? 次のコードはまさにそれを行います。それを機能させるには、QuartzCore フレームワークを追加する必要があります。

#import <QuartzCore/QuartzCore.h>

このコードは、三角形のシェイプ レイヤーを作成し、これをグラデーション レイヤーのマスクとして使用します。お役に立てれば。

- (void)drawRect:(CGRect)rect
{
    CGFloat w = self.bounds.size.width / 4;
    CGFloat h = self.bounds.size.height / 4;
    CGFloat x = w * 2;
    CGFloat y = h;
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path,NULL, x, y);
    CGPathAddLineToPoint(path, NULL, x+w, y+2*h);
    CGPathAddLineToPoint(path, NULL, x-w, y+2*h);
    CGPathCloseSubpath(path);


    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    [shapeLayer setPath:path];

    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    gradientLayer.startPoint = CGPointMake(0.25, 1.0);
    gradientLayer.endPoint = CGPointMake(0.75, 0.0);
    UIColor *startColour = [UIColor redColor];
    UIColor *endColour = [UIColor greenColor];
    gradientLayer.colors = [NSArray arrayWithObjects:(id)[startColour CGColor], (id)[endColour CGColor], nil];

    [gradientLayer setMask:shapeLayer];

    [self.layer addSublayer:gradientLayer];

    CGPathRelease(path);
}
于 2013-06-18T01:31:46.920 に答える