IPhone - How to animate a button when pressed?

Is there a way to make custom animation when I click on the iPhone button? I would like something like an App Store button - it shows the price, and then when you click on it, it changes color, and the text changes to purchase now, and then when you click it again, it completes the purchase.

UIViewAnimationTransition contains only a few values ​​that do not provide full functionality. Is it possible to do something similar, but with animation:

- (IBAction) changeButtonDisplay:(id)sender {

  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationDuration:0.8];
  [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:purchaseButton cache:NO]; //the built in UIViewAnimationTransition values don't provide enough flexibility

  [purchaseButton setTitle:@"Buy Now" forState:UIControlStateNormal];
  [purchaseButton setBackgroundColor:[UIColor greenColor]];
  [purchaseButton addTarget:self action:@selector(purchaseItems:) forControlEvents:UIControlEventTouchUpInside];

  [UIView commitAnimations];

}

, , . ​​ , UIButton ""? , ?

+3
3

, .. , , -. , , , - . UIView, .

, . , " ", , .

:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:buttonConteinerView cache:NO]; //the built in UIViewAnimationTransition values don't provide enough flexibility

[purchaseButton retain];
[purchaseButton removeFromSuperView];

[buttonContainerView addSubview:secondPurchaseButton];

[UIView commitAnimations];
+4

UIView , . UIView backgroundColor - .

"button" UIView OR UIButton . (: UIButtons 2.2, 3.0)

UILabel:

UILabel *textForStateOne;
UILabel *textForStateTwo;

.

, :

 -(void)toggleState{

myState = !myState;

  if(myState){

      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationDuration:0.8];

      [textForStateOne setAlpha:1.0]
      [textForStateTwo setAlpha:0.0]

      [self setBackgroundColor:[UIColor greenColor]];

      [UIView commitAnimations];


  } else{

       //do the opposite here

  }




}
+3
UIView *btnView4=button;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:btnView4 cache:YES];
[UIView commitAnimations];``
0
source

Source: https://habr.com/ru/post/1711036/


All Articles