1

    ストローク幅の異なる31個の円を描きたいです。拡大縮小できないため、再利用できないようです。すべての円には異なるオプションがあります。これらのビューは静的ではなく、View Controller をプッシュすると、常に再描画する必要があります。

更新されたセクション:

これは、 31 個の円を表示するように遷移したときの、 CircleView.mdrawRect:の私のメソッド    の Time Profiler のスクリーンショットです。

Time Profiler のスクリーンショット: 最適化を行わない 31 個の円を含むビューへの移行 ここに画像の説明を入力

    計画では、ユーザーはビューを頻繁に交換することになり、毎回再描画を待つのはかなり面倒になります。
    いくつかのカスタム コンテナー ビューがあります。残りの約 30% の時間は、ストーリーボードからの loadView に費やされます。それにもかかわらず、OtherTimeWasteView には subView:DatePickerView が 1 つしかないため、奇妙に思えますが、TProfile によると、実行時間は 84 ミリ秒で、[super loadView]メソッドに 100% が費やされます。

私の素朴な(?)最適化の試み:

    このビューを一度ロードし、parentViewController「combinedViewController」に保存して、常に再利用しようとしました。CircleView.hにプロパティを追加しました:

@property (strong,nonatomic) UIImage *imageCircle;

次に、callメソッド を追加して、 CircleView.mを    少し変更しました。-createImage

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.imageCircle=[self createImage];
    }
    return self;
}

-(UIImage*)createImage
{
    CGSize size=self.frame.size;

    UIGraphicsBeginImageContextWithOptions(size, NO, 1.0);

    CGContextRef contextRef = UIGraphicsGetCurrentContext();

    self.brush=0.6;

    CGRect frameOfCircle=CGRectMake(self.brush/2,self.brush/2, self.frame.size.width-self.brush-1.0f, self.frame.size.height-self.brush);
    // Draw a circle (border only)
    CGContextSetLineWidth(contextRef, self.brush);
    CGFloat mainColor[4]={23.0f/255.0f, 12.0f/255.0f, 0.0f, 0.5};
    CGContextSetStrokeColor(contextRef, mainColor);
    CGContextStrokeEllipseInRect(contextRef, frameOfCircle);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return image;

}

CombinedViewController.m:
ここでは、可視領域外の最初の 10 個の円を初期化しようとしています:

-(void)createCircles

    {
        self.arrayOfCircles=[[NSMutableArray alloc]init];
        for (int i=0; i<10; i++)
        {
            [self.arrayOfCircles addObject:[self circleViewWithRadius:530+i*35 withBrush:5+i tag:1014+i alphaParam:0.60]];
        }

    }

CirclesViewController.m にSubview を追加したい:

-(void)addCircles

    {
        CombinedViewController *parentVC=(CombinedViewController*)[self parentViewController];
        for (int i=0; i<10; i++)
        {

            CircleView *circle=(CircleView*)[parentVC.arrayOfCircles objectAtIndex:i];
            UIImageView *imgv=[[UIImageView alloc]initWithImage:circle.imageCircle];
            imgv.center=CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
            [self.view insertSubview:imgv belowView:someView];
        }


    }

-(void)viewWillAppear:(BOOL)animated
{
   [super viewWillAppear:animated];  
   [self addCircles];
}

a) 残念ながら、2 番目の方法を試しても円は追加されません。ブレークポイントでデバッグしましたが、arrayOfCircles は nil ではなく、円のイメージ プロパティも nil ではありません。しかし、私の視界にはまだ円がありません。私のコードに間違いはありますか?

b)事前に CGContext から画像を取得してパフォーマンスを最適化する適切な方法ですか? そうでない場合は、私の「a」の質問を無視して、高性能を適切に取得するためのヒントをいくつか教えてください。
まことにありがとうございます!

UPDATE2: リンク:
http://i.stack.imgur.com/EstBG.png
http://i.stack.imgur.com/uAjSJ.png
http://i.stack.imgur.com/Kw0cz.png

4

0 に答える 0