3

私はObjective-Cの開発にかなり慣れていません。ゼロから作成した最初のアプリでは、時間の経過とともにサイズが大きくなる円を描きたいと思います。問題は、画面上で円を移動できたのに、プロパティを更新できないように見えるため、円が大きくなったり小さくなったりすることです。

物事は次のようになります:

CCircle class

@interface CCircle : CShapes

@property float radius;
@property float startAngleRadians;
@property float endAngleRadians;

最初のビューコントローラ(ShapesViewController.m):

- (void) viewDidLoad
{
    (...)
    CCircle* circle = [[CCircle alloc] initWithFrame:frame];
    circle.radius = 40;
    circle.startAngleRadians = M_PI;
    circle.endAngleRadians = 2*M_PI;
    circle.tag = 1;
    [self.view addSubView:circle];

    //I also schedule an update method, so that it is called every 1 seconds.
    [NSTimer scheduledTimerWithTmieInterval:1.0 target:self selector:@selector(updateCircle) userInfo:nil repeats:YES];
}

また、ShapesViewController.mでは、更新メソッドは次のとおりです。

- (void) updateCircle
{
    CCircle *circle = [self.view viewWithTag:1];

    //Now here: if I do this: the circle will "move" through the screen
    CGRect frame = circle.frame;
    frame.origin.x += 5;
    [circle setFrame:frame];

    //However, if I try to change the circle properties, I don't know what to do so 
    //that affects the circle. In this case, the circle will move through the screen, 
    //but I keep seeing always the same size(radius).
    circle.radius += 5;

    //I've tried the following (of course, not all at the same time):
    //[self.vew addSubview:circle];
    //[self.view sendSubviewToBack:circle];
    //[self.view sendSubviewToFront:circle];
    //[self.view setNeedsDisplay];
    //[self.view setNeedsLayout];
}

私が間違っていること、そして私が望むことを達成するために私は何をすべきかについての助けはありますか?

ありがとう!

4

2 に答える 2

0

円を描いたら、ビューを更新する必要があります。

[self.view setNeedsDisplay];

それで済むと思います。

于 2012-10-04T09:03:04.287 に答える
0

circleではなくのプロパティを更新したself.viewため、 を呼び出す必要がありsetNeedsDisplayますcircle

于 2012-10-05T00:16:11.950 に答える