iOS开发中CALayer使用的基本教程

2020-01-14 17:52:10于丽

旋转一个弧度

复制代码
@implementation YYViewController

 

- (void)viewDidLoad
{
    [super viewDidLoad];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    //通过uiview设置(2D效果)
//    self.iconView.transform=CGAffineTransformMakeTranslation(0, -100);
    //通过layer来设置(3D效果,x,y,z三个方向)
//    self.iconView.layer.transform=CATransform3DMakeTranslation(100, 20, 0);
    
    //通过KVC来设置
//    NSValue *v=[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(100, 20, 0)];
//    [self.iconView.layer setValue:v forKeyPath:@"transform"];
//    //如果是只需要设置在某一个方向上的移动,可以参考下面的代码
//    //在x的方向上向左移动100
//    [self.iconView.layer setValue:@(-100) forKeyPath:@"transform.translation.x"];
    
    //旋转
    self.iconView.layer.transform=CATransform3DMakeRotation(M_PI_4, 1, 1, 0.5);
}


 

iOS开发中CALayer使用的基本教程

补充:三维坐标系

iOS开发中CALayer使用的基本教程



注:相关教程知识阅读请移步到IOS开发频道。