我有一个 UIViews 数组,我想以网格形式将它们排列在主视图中,并且我还希望它具有动画效果(即网格应该一个一个缓慢地出现)。尝试在 for 循环中制作动画,但没有奏效,但想出了一个变通方法来实现更接近我想要的东西,但只是想知道是否有更好的方法来做到这一点。我知道 CAAnimationGroup (begintime) 有一些属性,但确定如何将它连接到 addtosubview。这是我的代码,如果有更好的方法,请告诉我。
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
CGFloat x = 0;
CGFloat delay = .3;
for(int i=0;i<30;i++)
{
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(x, 0, 50, 50)];
myView.backgroundColor = [UIColor greenColor];
myView.alpha = 0.0;
x = x + 50+ 2;
[UIView animateWithDuration:0.25 delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:^{
[self.view addSubview:myView];
myView.transform = CGAffineTransformMakeScale(0.5, 0.5);
// myView.transform = CGAffineTransformMakeRotation(90);
} completion:^(BOOL finished) {
[UIView animateWithDuration:.5 animations:^{
myView.transform = CGAffineTransformMakeScale(1.0, 1.0);
myView.alpha = 1.0;
}];
}];
delay = delay + .3;
}
// Do any additional setup after loading the view, typically from a nib.
}
-anoop