你的问题必须在别处解决。我测试了一个绘制圆圈的简单自定义视图:
@interface CircleView ()
@property (nonatomic) CFAbsoluteTime startTime;
@end
@implementation CircleView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_startTime = CFAbsoluteTimeGetCurrent();
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CFAbsoluteTime elapsed = CFAbsoluteTimeGetCurrent() - self.startTime;
float seconds;
float fractionsOfSecond = modff(elapsed, &seconds);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextAddArc(context, self.bounds.size.width * fabs(fractionsOfSecond - 0.5) * 2.0, self.bounds.size.height / 2.0, 10.0, 0, M_PI * 2.0, YES);
CGContextDrawPath(context, kCGPathStroke);
}
@end
我将其中三个添加到滚动视图并启动了一个计时器:
@interface ViewController ()
@property (nonatomic, strong) NSMutableArray *circles;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// add three circle views
CircleView *circle;
CGRect frame = self.view.bounds;
CGFloat height = frame.size.height / 3.0;
frame.size.height = height;
self.circles = [NSMutableArray arrayWithCapacity:3];
for (int i = 0; i < 3; i++)
{
circle = [[CircleView alloc] initWithFrame:frame];
circle.backgroundColor = [UIColor clearColor];
[self.scrollView addSubview:circle];
self.circles[i] = circle;
frame.origin.y += height;
}
// start timer
NSTimer *timer = [NSTimer timerWithTimeInterval:1.0/30.0
target:self
selector:@selector(handleTimer)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
- (void)handleTimer
{
// show the time so I can see the timer in action
static NSDateFormatter *formatter = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"HH:mm:ss.SSS";
});
self.timeLabel.text = [formatter stringFromDate:[NSDate date]];
// let's update three circles
for (UIView *view in self.circles)
[view setNeedsDisplay];
}
@end
它在第 4 代 iPod Touch 上运行良好。也许您可以分享您的一些代码,我们可以确定问题的根源。