Как оживить изображение с помощью uibuttons - PullRequest
0 голосов
/ 07 марта 2012

У меня есть три uibuttons с именами 1,2 и 3, и справа внизу этих кнопок у меня есть изображение стрелки, которое указывает на то, какая кнопка нажата в данный момент.Я хочу, чтобы, когда я нажимал любую кнопку, стрелка начинала анимироваться и скользила внизу кнопки, которая нажата.

Ответы [ 3 ]

0 голосов
/ 07 марта 2012

Подключите все ваши кнопки к одному методу или в методе, который реагирует на каждое нажатие кнопки, также вызовите этот метод.

0 голосов
/ 07 марта 2012

Выполните следующие действия при нажатии кнопки:

// For Button 1
- (IBAction)pressedButton1:(id)sender{

        // Create an animation lasting 1 second
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.00];
        [UIView setAnimationDelegate:self];

        // Set your arrow image view's center x property to that of the button
        myArrowImageView.center = CGPointMake(myButton1.center.x, myArrowImageView.center.y);

        [UIView commitAnimations];

}

// For Button 2
- (IBAction)pressedButton2:(id)sender{

    // Create an animation lasting 1 second
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.00];
    [UIView setAnimationDelegate:self];

    // Set your arrow image view's center x property to that of the 2nd button
    myArrowImageView.center = CGPointMake(myButton2.center.x, myArrowImageView.center.y);

    [UIView commitAnimations];

}

// For Button 3
- (IBAction)pressedButton3:(id)sender{

    // Create an animation lasting 1 second
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.00];
    [UIView setAnimationDelegate:self];

    // Set your arrow image view's center x property to that of the 3rd button
    myArrowImageView.center = CGPointMake(myButton3.center.x, myArrowImageView.center.y);

    [UIView commitAnimations];

}

PS Всегда полезно также публиковать исходный код, когда вы задаете вопрос.Это помогает людям дать вам лучший ответ.

0 голосов
/ 07 марта 2012
  • (void) setImage: (UIImage *) image forState: (UIControlState) состояние;

и выберите UIControlState из

enum {
UIControlStateNormal       = 0,                       
UIControlStateHighlighted  = 1 << 0,                  // used when UIControl isHighlighted is set
UIControlStateDisabled     = 1 << 1,
UIControlStateSelected     = 1 << 2,                  // flag usable by app (see below)
UIControlStateApplication  = 0x00FF0000,              // additional flags available for application use
UIControlStateReserved     = 0xFF000000               // flags reserved for internal framework use
};
typedef NSUInteger UIControlState;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...