view的一些旋转动画

在做动画时,uiview的旋转方向可以这样控制

CGAffineTransform transform = CGAffineTransformMakeRotation(x * M_PI/180.0);

若想顺时针,则x为正数,如30;若想逆时针,则x为负数即可,如-30
还有旋转的原点,即以哪个点为圆心来旋转。这个点的选择与平常的坐标系不同,需要用到layer。
如以imageView的左下角为圆心转,则有

_folatImageView.layer.anchorPoint = CGPointMake(0, 1);
// (0, 0)指左上角, (1,1)指右下角, (0.5,0.5)指中心点,以此类推

如若让imageView以左下角按逆时针转动,则有

_folatImageView.layer.anchorPoint = CGPointMake(0, 1);
//从原位逆时针转一定角度
-(void)floatUp{
    [UIView animateWithDuration:1.0f animations:^{
        _folatImageView.layer.transform = CATransform3DMakeRotation(-20 * M_PI/180.0, 0, 0, 1);
    } completion:^(BOOL finished) {
            
    }];
}
//恢复原位
-(void)floatDown{
    [UIView animateWithDuration:1.0f animations:^{
        _folatImageView.layer.transform = CATransform3DMakeRotation(0, 0, 0, 0);
    } completion:^(BOOL finished) {
            
    }];
}

 

对于view的旋转,还有(默认以中心顺时针旋转)
①旋转到x度

view.transform = CGAffineTransformMakeRotation(x);

②在现有旋转的度数上再旋转x度

CGAffineTransform currentTransform = view.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, x); // 在现在的基础上旋转指定角度
view.transform = newTransform;

③恢复到原位,即0度

view.transform = CGAffineTransformMakeRotation(0);

 

在做一些简单的动画,如图

可以用如下代码
先定义_testView

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 80, mScreenWidth, 0.1)];
view.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:view];
_testView = view;
//点击按钮时的动画
-(void)clickTheBtn:(UIButton *)btn{
    if (_testOpened) {
        [UIView animateWithDuration:1.0f animations:^{
            _testView.height = 0.1;
        }];
    } else {
        [UIView animateWithDuration:1.0f animations:^{
            _testView.height = 200;
        }];
    }
    _testOpened = !_testOpened;
    //下滑箭头的倒置
    _testBtn.transform = CGAffineTransformRotate(_testBtn.transform, M_PI);
}

由上可以看出,view的伸展收缩动作只需改变其高度即可。

转载于:https://www.cnblogs.com/Apologize/p/5286316.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值