zoukankan      html  css  js  c++  java
  • 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的伸展收缩动作只需改变其高度即可。

  • 相关阅读:
    新MGDN论坛(NewMGDN.com)重新上线
    从MapGuide Enterprise 2010针对XSS的的安全补丁看.Net 编程的安全性
    Map 3D 2010 开发中的OnCheckIn事件处理
    Windows 7上开发MapGuide时的安装问题
    Maestro的最近进展
    “Sharing Position with Friends” in MGE based Web GIS Application
    预告5月28号:Autodesk MapGuide Enterprise 2011 API 新功能培训
    Improvement for “Sharing Position with Friends” in MGE based Web GIS Application
    AutoCAD Map3D 改进意见征集活动
    Windows 7 Tips! 透明缓存(transparent caching)技术
  • 原文地址:https://www.cnblogs.com/Apologize/p/5286316.html
Copyright © 2011-2022 走看看