我现在想实现这样的效果,一个按钮平滑地从一个位置滑动到另一个位置,请问这个可以通过动画效果实现吗?具体要怎么做呢,谢谢!

解决方案 »

  1.   


    + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); // delay = 0.0, options = 0+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); // delay = 0.0, options = 0, completion = NULL这三个动画函数即可。把按钮的frame改变一下。
      

  2.   

    我使用了如下代码,实现每次点击背景,按钮平滑移动,但是只有第一次点击的时候按钮是平滑地移动。- (void)move
    {
        __block CGRect rect = button.frame;
        
        [UIView animateWithDuration:0.5
                         animations:^{
                             //button.transform = CGAffineTransformMakeRotation(3.14);
                             button.transform = CGAffineTransformMakeTranslation(20, 20);
                         }
                         completion:^(BOOL finished){
                             rect.origin.x+=20;
                             rect.origin.y+=20;
                             button.frame = rect;
                         }];
    }
    - (IBAction)bkTap:(id)sender
    {
        [self move];
    }
      

  3.   

    fOffsetX,fOffsetY表示移动的话,代码这么写就对了:
    fOffsetX+=20;
    fOffsetY+=20;
    CGAffineTransformMakeTranslation(fOffsetX, fOffsetY);
      

  4.   

    soga。。受教了!