我对动画一无所知,我已经使用了很多建议的动画,但没有按照我的要求工作。我有一个根据字长显示的 UIButtons 序列,即每个按钮都包含一个字符那个词。所以我想做的是在放置词本身时,我希望按钮来自右侧并回到它们提到的位置(坐标)。这是我创建等于词长的按钮的方法。
-(void)buttonsCreation:(int)noOfButtons
{
for (UIView *view in self.view.subviews)
{
if ([view isKindOfClass:[UIButton class]])
{
if (view.tag >=100)
{
[view removeFromSuperview];
}
}
}
NSMutableArray *charactersArray = [NSMutableArray array];
self.wordButtons = [[NSMutableArray alloc]initWithCapacity:30];
BOOL record = NO;
int randomNumber;
for (int i=0; [charactersArray count] < jumbledWord.length; i++) //Loop for generate different random values
{
randomNumber = arc4random() % jumbledWord.length;//generating random number
if(i==0)
{
[charactersArray addObject:[NSNumber numberWithInt:randomNumber]];
}
else
{
for (int j=0; j<= [charactersArray count]-1; j++)
{
if (randomNumber ==[[charactersArray objectAtIndex:j] intValue])
record = YES;
}
if (record == YES)
record = NO;
else
[charactersArray addObject:[NSNumber numberWithInt:randomNumber]];
}
}
int arrayValue;
float x = 60.0;
float y = 50.0;
for(int i=0;i<[jumbledWord length];i++)
{
if(i>=0 && i<10)
{
arrayValue = [[charactersArray objectAtIndex:i] intValue];
x = x + 37;
UIButton *characterButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
characterButton.frame = CGRectMake(x,175.0, 35.0, 35.0);
[wordButtons addObject:characterButton];
NSString *characterValue = [NSString stringWithFormat:@"%c",[jumbledWord characterAtIndex:arrayValue]];
[characterButton setTitle:characterValue forState:UIControlStateNormal];
[characterButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
if (arrayValue==0)
{
arrayValue = 100;
}
[characterButton setTag:arrayValue*100];
[self.view addSubview:characterButton];
}
else if(i>=10 && i<20)
{
arrayValue = [[charactersArray objectAtIndex:i] intValue];
y = y + 37;
UIButton *characterButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
characterButton.frame = CGRectMake(y,200.0, 35.0, 35.0);
[wordButtons addObject:characterButton];
NSString *characterValue = [NSString stringWithFormat:@"%c",[jumbledWord characterAtIndex:arrayValue]];
[characterButton setTitle:characterValue forState:UIControlStateNormal];
[characterButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
if (arrayValue==0)
{
arrayValue = 100;
}
[characterButton setTag:arrayValue*100];
[self.view addSubview:characterButton];
}
}
}
PS -* Off post *:我正在使用下面的代码从视图中关闭按钮序列,然后带来下一个按钮序列,即下一个单词
for (UIView *view in self.view.subviews)
{
if ([view isKindOfClass:[UIButton class]])
{
if (view.tag >=100)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.30f];
view.transform =
CGAffineTransformMakeTranslation(
view.frame.origin.x,
480.0f + (view.frame.size.height/2) // move the whole view offscreen
);
[UIView commitAnimations];
}
}
}
有人可以指导我吗,谢谢:)