我在我的应用程序中动态创建 UIButton。当我显示按钮时,我想为它们设置动画。我似乎无法让按钮使用此代码进行动画处理:
UIImage *buttonBackground = [UIImage imageNamed:@"ButtonRed.png"];
for (NSInteger x = 0; x < 4; x++) {
CGRect btnFrame = CGRectMake(x * (buttonBackground.size.width+2),
y * (buttonBackground.size.height + 1),
buttonBackground.size.width,
buttonBackground.size.height);
UIButton *gridButton = [[[UIButton alloc] initWithFrame: btnFrame] retain];
[gridButton setBackgroundImage:buttonBackground forState:UIControlStateNormal];
[buttonBackground release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:gridButton cache:YES];
[self.view addSubview:gridButton];
[UIView commitAnimations];
[gridButton release];
}
如果我将“forView:gridButton”更改为“forView:self.view”,则整个视图会翻转,但不会翻转单个按钮。我只希望每个单独的按钮都翻转。
谢谢你的帮助。