Привет, я начинаю с iOS, и у меня есть вопрос.Анимация нескольких UIButtons
Я хочу, чтобы повторно организовать несколько кнопок при изменении ориентации, так я этот код, чтобы создать их:
NSArray *buttonImages = [[NSArray alloc] initWithObjects:@"button_1.png",@"button_2.png",
@"button_3.png", @"button_4.png", nil];
int xcord = 0;
//int ycord = 0;
UIInterfaceOrientation destOrientation = self.interfaceOrientation;
if (destOrientation == UIInterfaceOrientationPortrait || destOrientation == UIInterfaceOrientationPortraitUpsideDown) {
screenWidth = 768;
} else {
screenWidth = 1024;
}
int buttonWidth = 57;
int buttonHeight = 86;
int screenHorizontalDivisions = screenWidth/5;
for (int i=0; i<4; i++) {
int buttonStartingOffset = screenHorizontalDivisions - buttonWidth/2;
btn = [[DashButton alloc] initWithFrame:CGRectMake(buttonStartingOffset + xcord, 40, buttonWidth,buttonHeight) andImage:[buttonImages objectAtIndex:i] andTitle:@"Test"];
btn.tag = i+1;
[springboardScrollView addSubview:btn];
//[btn release];
xcord = xcord + screenHorizontalDivisions;
}
и код повторно организовать их является:
- (void)animate: (id)sender {
UIButton *button = (UIButton *)sender;
UIInterfaceOrientation destOrientation = self.interfaceOrientation;
if (destOrientation == UIInterfaceOrientationPortrait || destOrientation == UIInterfaceOrientationPortraitUpsideDown) {
screenWidth = 768;
} else {
screenWidth = 1024;
}
int xcord = 0;
int buttonWidth = 57;
int buttonHeight = 86;
int screenHorizontalDivisions = screenWidth/5; //find the divisions
int buttonStartingOffset = screenHorizontalDivisions - buttonWidth/2; //center the button
NSLog (@"%i", button.tag);
switch (button.tag) {
case 1:
button.frame = CGRectMake(buttonStartingOffset, 40, buttonWidth,buttonHeight);
break;
case 2:
button.frame = CGRectMake(buttonStartingOffset + screenHorizontalDivisions, 40, buttonWidth,buttonHeight);
break;
case 3:
button.frame = CGRectMake(buttonStartingOffset + screenHorizontalDivisions * 2, 40, buttonWidth,buttonHeight);
break;
case 4:
button.frame = CGRectMake(buttonStartingOffset + screenHorizontalDivisions * 3, 40, buttonWidth,buttonHeight);
break;
}
тогда я звоню при изменении ориентации:
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation duration: (NSTimeInterval) duration {
[self animate:btn];
Как я могу ссылаться на каждую кнопку по одному? Код в анимации: всегда возвращает button.tag = 4.
Пожалуйста, помогите !!
Thanks Bill.