ios学习笔记之十--center和bounds的使用

标题  center和bounds的使用

主题


执行动态控制图片移动,步进移动

在viewcontroller.m中

-(void)move:(UIButton *)btn{

    

    //执行动态控制图片移动,步进移动

    //在头部开启动后,在尾部结束动画即可

    

    //0.开启动画

    [UIView beginAnimations:nil context:nil];

    //设置动画的时间

    //默认的动画太快,看不出效果

    [UIView setAnimationDuration:2.0];

    

    //if(btn.frame.origin.x = )

    //不能这么通过按钮的坐标判断

    

    //通过给按钮取名(设置tag值来区分按钮)tag值一般是整数,设定

    //上的tag=10

//    下 tag = 20

//    左 tag = 30

//    右 tag = 40

    //取出临时值

    CGRect tempFrame = self.head.frame;

    //临时值变化

    //此处也可以用if语句,但是可读性差,一般只有一级if  else

    CGFloat margin = 10;


    switch (btn.tag) {

        case 10:

            tempFrame.origin.y -= margin;

            break;

        case 20:

            tempFrame.origin.y += margin;

            break;

        case 30:

            tempFrame.origin.x -= margin;

            break;

        case 40:

            tempFrame.origin.x += margin;

            break;

    }

    //3.覆盖原值

    self.head.frame = tempFrame;

    //提交动画

    [UIView commitAnimations];

}





bounds 的使用(边框)

-(void)small{

    CGRect tempBounds = self.head.bounds;

    //此时无法放大图片

    tempBounds.size.width -= 10;

    tempBounds.size.height -= 10;

    self.head.bounds = tempBounds;


}


center的使用(中心点)跟frame移动形式差不多

//取出临时值

    CGPoint tempCenter = self.head.center;

    //临时值变化

    //此处也可以用if语句,但是可读性差,一般只有一级if  else

    CGFloat margin = 10;


    switch (btn.tag) {

        case 10:

            tempCenter.y -= margin;

            break;

        case 20:

            tempCenter.y += margin;

            break;

        case 30:

            tempCenter.x -= margin;

            break;

        case 40:

            tempCenter.x += margin;

            break;

    }

    //3.覆盖原值

    self.head.center = tempCenter;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值