UIViewController-UIView-CGRect-frame

//定义常量

#define runTime 1.0

#define kDetal 50

 

//frame

- (IBAction)run:(id)sender {

    //初始化动画

    [UIViewbeginAnimations:nilcontext:nil];

    //设置动画执行速度

    [UIViewsetAnimationDuration:runTime];

    //获取当前btn.frame的x.y

    CGRect tempFrame = _btn.frame;

    //获取当前传进来的空间的tag属性

    int tag = [sender tag];

    

    switch (tag) {

        case 1:

            //设置frame的y

            tempFrame.origin.y -= kDetal;

            break;

        case 2:

            tempFrame.origin.x += kDetal;

            break;

        case 3:

            tempFrame.origin.y += kDetal;

            break;

        case 4:

            tempFrame.origin.x -= kDetal;

            break;

            

        default:

            break;

    }

    

    _btn.frame = tempFrame;

    

    [UIViewcommitAnimations];

    

}

猜你喜欢

转载自vip-samuel.iteye.com/blog/2204121