- (void)viewDidLoad
{
[super viewDidLoad];
board=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, 80)];
board.backgroundColor=[UIColor greenColor];
[self.view addSubview:board];
// Do any additional setup after loading the view.
}
-(void)viewDidLayoutSubviews
{
NSString *str=@"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
index=1;
for (int i=0; i<20; i++)
{
UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(-50, 15, 50, 50)];
lbl.tag=i+1;
lbl.text=[NSString stringWithFormat:@"%c",[str characterAtIndex:arc4random()%str.length]];
lbl.textColor=[UIColor darkGrayColor];
lbl.textAlignment=NSTextAlignmentCenter;
lbl.font=[UIFont systemFontOfSize:40];
lbl.layer.borderWidth=1;
lbl.layer.borderColor=[UIColor blackColor].CGColor;
[board addSubview:lbl];
}
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(CallAnimation) userInfo:nil repeats:YES];
NSLog(@"%d",[board subviews].count);
}
-(void)CallAnimation
{
if (index>20) {
index=1;
}
UIView *aView=[board viewWithTag:index];
[self doAnimation:aView];
index++;
NSLog(@"%d",index);
}
-(void)doAnimation:(UIView*)aView
{
[UIView animateWithDuration:10 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
aView.frame=CGRectMake(self.view.frame.size.height, 15, 50, 50);
}
completion:^(BOOL isDone)
{
if (isDone) {
//do Somthing
aView.frame=CGRectMake(-50, 15, 50, 50);
}
}];
}