Wednesday, 11 September 2013

Showing every 5 seconds a new UIImageView with the help of NSTimer and UIView Animation?

Showing every 5 seconds a new UIImageView with the help of NSTimer and
UIView Animation?

I am trying to create a Calibration View! I have 12 calibration points as
UIImageViews. Now I want to show every point for 5 seconds. So the whole
calibration time is 1 minute. The Alpha of the ImageViews is set to 0.0!
In the UI Animation I want to set the Alpha to 1.0 for one point after an
other, for each point only for 5 seconds.
So far I did this (see the code)! But this animates me (fades in) after 5
seconds for 5 seconds all 12 Points at once!How can I solve this for one
after another with a NSTimer and UI Animation? Thanks

-(id)init{
_calibrationViewArray = [[NSMutableArray alloc]init];
_calibrationPoint1 = [[UIImageView
alloc]initWithFrame:(CGRectMake(115.5,113.0,25.0,25.0))];
_calibrationPoint1.backgroundColor = [UIColor redColor];
_calibrationPoint1.alpha = 0.0;
[self addSubview:_calibrationPoint1];
[_calibrationViewArray addObject:_calibrationPoint1];
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self
selector:@selector(onTimer) userInfo:nil repeats:YES];
}
-(void)onTimer{
for (int i = 0; i < [_calibrationViewArray count]; i++) {
UIImageView* currentCalibrationPoint = [_calibrationViewArray
objectAtIndex:i];
[UIView beginAnimations:@"Calibration" context:nil];
[UIView setAnimationDuration:5.0];
// Make the animatable changes.
currentCalibrationPoint.alpha = 1.0;
// Commit the changes and perform the animation.
[UIView commitAnimations];
}
}

No comments:

Post a Comment