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, not的属性,self.view因此您需要调用setNeedsDisplay.circle

于 2012-10-05T00:16:11.950 回答