2017-06-29 8 views
0

Ändern Sie die Position, wenn es gedrückt wird. UIButton * button = sender;Wie ändert man die Position der Taste mit der Animation

CGPoint position = button.frame.origin; 
[UIButton setAnimationDuration:1.0]; 

CGSize size = button.frame.size; 
button.frame = CGRectMake(position.x + 80,position.y,size.width,size.height); 
+0

https://developer.apple.com/documentation/uikit/uiview/1622418-animate – RJiryes

+1

haben Sie Ihre Antworten? –

Antwort

0

Try this:

button.frame = CGRectMake(position.x + 80,position.y,size.width,size.height); // initial frame 

[UIView animateWithDuration:2 animations:^{ 
      button.frame = CGRectMake(position.x + 80,position.y,size.width,size.height); // new frame frame 

     } completion:^(BOOL finished) { 

     }]; 
2

Try this:

[UIView animateWithDuration:1.0 animations:^{ 
    btn.frame = CGRectOffset(btn.frame, 0, 20); 
}]; 
0

Sie Animationsblock UIView Klasse verwenden können ...

was auch immer Sie den Rahmen in diesem Block ändern Füllen Sie den Rahmen zwischen Legen Sie den Startrahmen fest

button.frame= yourInitialFrame;

[UIView animateWithDuration:1.0 animations:^{ 
    // set the End Frame here 
       button.frame = CGRectMake(position.x + 
      80,position.y,size.width,size.height); // new frame frame 

      } completion:^(BOOL finished) { 

      }]; 

auch diese diese see this für weitere Hilfe siehe

1

Für Animieren die Position UIButton mit Dauer 1,0 Sekunden

 CGPoint position = button.frame.origin; 
     CGSize size = button.frame.size; 

     -(IBAction)btnClick:(id)sender { 
       [UIView animateWithDuration:1.0 animations:^{ 
        button.frame = CGRectMake(position.x+80,position.y,size.width,size.height); 
       }]; 
     } 
0
[UIView animateWithDuration:1.0 animations:^{ 
    // set the End Frame here 
       button.frame = CGRectMake(position.x + 
      80,position.y,size.width,size.height); // new frame frame 

      } completion:^(BOOL finished) { 

      }]; 
0
 [UIView animateWithDuration:0.2 animations:^{ 
     CGRect rect = button.frame; 
     rect.origin.x = rect.origin.x + 80; 
     button.frame = rect; 
    } completion:^(BOOL finished) { 

    }]; 
+1

Während dieser Code die Frage beantworten kann, würde das Bereitstellen eines zusätzlichen Kontextes, wie und/oder warum er das Problem löst, den langfristigen Wert der Antwort verbessern. –

Verwandte Themen