• iOS视图弹出、平移、旋转、翻转、剪切等变换效果实现


    效果图:

    1、定义属性

    @property (nonatomic, strong) UIView        *transformView;//发生变换的试图
    
    @property (nonatomic, strong) UIView        *backGroundView;//发生变换试图的父试图
    
    @property (nonatomic, strong) UITableView   *titleTableView;
    
    @property (nonatomic, strong) NSArray       *dataSourceAry;//数据源数组
    

      

    2、实现代码

    -(void)poppingViewWithTransform:(NSString *)transformStr{
        
        
        [self.view addSubview:self.backGroundView];
        
        
        self.transformView.frame = CGRectMake(SCWidth/2-100, 200, 200, 200);
        
        if ([transformStr isEqualToString:@"缩放变换"]) {
             //很简单的变换效果,200,为Y轴从下往上平移,相反-200 是从上往下平移
            self.transformView.transform = CGAffineTransformMakeScale(0.0, 0.0);
            [UIView animateWithDuration:0.5 animations:^{
                self.transformView.transform = CGAffineTransformMakeScale(1.0, 1.0);
                
            }];
            
        }else if([transformStr isEqualToString:@"平移变换"]){
            //很简单的变换效果,200,为Y轴从下往上平移,相反-200 是从上往下平移,X轴变换同理
            self.transformView.transform = CGAffineTransformMakeTranslation(0, -200);
            [UIView animateWithDuration:0.5 animations:^{
                self.transformView.transform = CGAffineTransformMakeTranslation(0,0);
            }];
        }else if([transformStr isEqualToString:@"翻转变换"]){
            //下面注释的代码,最后Z轴改成一个数字,例12,可以实现旋转变换
            //self.transformView.layer.transform = CATransform3DMakeRotation(12, 1, 1, 0);
            self.transformView.layer.transform =  [self firstStep];
            
            [UIView animateWithDuration:0.5 animations:^{
                self.transformView.layer.transform = CATransform3DMakeRotation(0, 1, 0, 0);
            }];
        }else if([transformStr isEqualToString:@"旋转变换"]){
            //具体效果可以更改 M_PI_4 角度来实现
            self.transformView.transform = CGAffineTransformMake(( cos(M_PI_4) ), ( sin(M_PI_4) ), -( sin(M_PI_4) ), (cos(M_PI_4) ), 0, 0);
            [UIView animateWithDuration:0.5 animations:^{
                self.transformView.transform = CGAffineTransformMake(( cos(M_PI) ), ( sin(M_PI) ), -( sin(M_PI) ), (cos(M_PI) ), 0, 0);
            }];
        }else if([transformStr isEqualToString:@"剪切变换"]){
            //使用仿射基础方法CGAffineTransformMake,设置x和y都为0.5的斜切
            //可以试着把第一个1换成0.5,看看效果
            //可以试着把第二个1换成0.5,看看效果
            self.transformView.transform =  CGAffineTransformMake(1,0.5,0.5,1,0,0);
            [UIView animateWithDuration:0.5 animations:^{
                self.transformView.transform = CGAffineTransformMake(1,0,0,1,0,0);
            }];
        }
        
        
        self.transformView.layer.cornerRadius = 7;
        self.transformView.layer.masksToBounds = YES;
        [self.backGroundView addSubview:self.transformView];
    」
    

      

    其中,翻转变化用到这个:

    -(CATransform3D)firstStep{
        //让transform1为单位矩阵
        CATransform3D transform1 = CATransform3DIdentity;
        //z轴纵深的3D效果和CATransform3DRotate配合使用才能看出效果
        //m34很重要
        transform1.m34 = 1.0/-100;
        //x和y都缩小为原来的0.9,z不变
        transform1 = CATransform3DScale(transform1, 0.9, 0.9, 1);
        //绕x轴向内旋转15度
        transform1 = CATransform3DRotate(transform1,15.0f * M_PI/180.0f, 1, 0, 0);
        return transform1;
    }
    

      

  • 相关阅读:
    2016/11/17 周四 <javascript的封装简单示例>
    JavaScript资源大全中文版(Awesome最新版转载自张果老师博客)
    <web Font的使用>
    博客园首页飘彩色雪花代码
    C#多线程
    SQL Server数据库优化措施:索引优化(转)
    HOWTO: InstallShield中如何实现MSI包的权限提升(转)
    C# 获取操作系统版本信息
    installshield msi程序安装问题
    bat和VBS
  • 原文地址:https://www.cnblogs.com/yajunLi/p/6084724.html
Copyright © 2020-2023  润新知