153,改变控件的位置,缩放大小与旋转角度

来源:互联网 发布:python的语法结构 编辑:程序博客网 时间:2024/05/29 11:34

/*

 一般来说,改变按钮的位置,缩放大小与旋转角度可以采用:

 bounds:改变其宽长,以致改变其大小

 center:改变其中心点,以改变其位置

 transform:即可以改变其位置,缩放大小与旋转角度

 frame常用于控件初始化,其他应用比较少。

 */


//位置移动

- (IBAction)move:(UIButton *) button {

    int tx = 0,ty =0;

    if (button.tag ==10 || button.tag ==12) {

        ty = (button.tag == 10)? -20:20;

    }else{

        tx = (button.tag == 11)? -20:20;

    }

    [UIViewbeginAnimations:nilcontext:nil];

    [UIViewsetAnimationDuration:0.5];

    self.iconP.transform = CGAffineTransformTranslate(self.iconP.transform,tx,ty);

    [UIViewcommitAnimations];

}


//缩放大小

- (IBAction)zoon:(UIButton *)button {

    float sx = 0,sy =0;

    button.tag?(sx = 1.2,sy = 1.2):(sx = 0.8,sy = 0.8);

    [UIViewbeginAnimations:nilcontext:nil];

    [UIViewsetAnimationDuration:0.5];

    self.iconP.transform =CGAffineTransformScale(self.iconP.transform, sx, sy);

    [UIViewcommitAnimations];

}


//旋转角度

-(IBAction)rotate:(UIButton *)button{

    int rotate = 0;

    button.tag? (rotate = 1):(rotate = -1);

    [UIViewbeginAnimations:nilcontext:nil];

    [UIViewsetAnimationDuration:0.5];

     self.iconP.transform =CGAffineTransformRotate(self.iconP.transform,M_PI_4*rotate);

    [UIViewcommitAnimations];

}


0 0
原创粉丝点击