如何使用动画更改按钮的位置

时间:2017-06-29 08:50:49

标签: ios objective-c

按下时改变位置。 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);

7 个答案:

答案 0 :(得分:3)

试试这个:

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

答案 1 :(得分:1)

UIButton的位置设置动画,持续时间为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);
                }];
        }

答案 2 :(得分:0)

试试这个:

googleMarker.addListener('click', function() {...}

答案 3 :(得分:0)

您可以使用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以获取更多帮助

答案 4 :(得分: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) {

            }];

答案 5 :(得分:0)

试试这个:

-(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?

Moving UIButton position, animated

答案 6 :(得分:0)

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

    }];