当按下时更改位置。 UIButton * button = sender;如何更改动画按钮的位置
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);
当按下时更改位置。 UIButton * button = sender;如何更改动画按钮的位置
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);
试试这个:
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) {
}];
试试这个:
[UIView animateWithDuration:1.0 animations:^{
btn.frame = CGRectOffset(btn.frame, 0, 20);
}];
你可以使用UIView
类的动画块...
不管你更改此块内的框架,画布填充框架在 之间设置开始框架
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) {
}];
也看到这个see this更多的帮助
对于1.0秒
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);
}];
}
[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) {
}];
试试这个动画的UIButton
位置与时间:
-(IBAction)ButtonClick:(id)sender
{
UIButton *aBtnRef = sender;
[UIView animateWithDuration:0.5 animations:^{
aBtnRef.frame = CGRectMake(aBtnRef.frame.origin.x + 50,aBtnRef.frame.origin.y, aBtnRef.frame.size.width, aBtnRef.frame.size.height);
} completion:^(BOOL finished) {
}];
}
获取更多信息:
Animation : How to make UIbutton move from right to left when view is loaded?
[UIView animateWithDuration:0.2 animations:^{
CGRect rect = button.frame;
rect.origin.x = rect.origin.x + 80;
button.frame = rect;
} completion:^(BOOL finished) {
}];
尽管此代码可能会回答问题,但提供有关如何解决问题和/或解决问题原因的其他上下文会提高答案的长期价值。 –
https://developer.apple.com/documentation/uikit/uiview/1622418-animate – RJiryes
你领回答? –