IOS開發圖層CALayer的基本屬性使用

  1. 利用圖層設置裁剪圓形頭像,該方法比用圖形上下文性能高不少性能

- (void)imageLayer
{
    // 圓形裁剪
    _imageView.layer.cornerRadius = 50;
    
    // 超出layer邊框的所有裁剪掉
    _imageView.layer.masksToBounds = YES;
    //設置邊框顏色
    _imageView.layer.borderColor = [UIColor whiteColor].CGColor;
    //設置邊框寬度
    _imageView.layer.borderWidth = 2;
    
}

2.圖層的另一些屬性code

- (void)viewLayer
{
    // 設置陰影透明度
    _redView.layer.shadowOpacity = 1;
    
    // 設置陰影顏色
    _redView.layer.shadowColor = [UIColor yellowColor].CGColor;
    
    // 設置陰影圓角半徑
    _redView.layer.shadowRadius = 10;
    
    // 設置圓角半徑
    _redView.layer.cornerRadius = 50;
    
    // 設置邊框半徑
    _redView.layer.borderColor = [UIColor whiteColor].CGColor;
    
    // 設置邊框半徑
    _redView.layer.borderWidth = 2;
}

3.利用圖層改變形變orm

        // 縮放
        _imageView.layer.transform = CATransform3DMakeRotation(M_PI, 1, 1, 0);
      //   平移
        _imageView.layer.transform = CATransform3DMakeTranslation(200, 200, 0);
        
   //      縮放
        _imageView.layer.transform = CATransform3DMakeScale(0.5, 0.5, 1);
     
    // 利用KVC改變形變
        
     NSValue *rotation = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 1, 1, 0)];

        [_imageView.layer setValue:rotation forKeyPath:@"transform"];
        
        [_imageView.layer setValue:@M_PI forKeyPath:@"transform.rotation"];

        [_imageView.layer setValue:@0.5 forKeyPath:@"transform.scale"];
        
        // 平移x軸
        [_imageView.layer setValue:@200 forKeyPath:@"transform.translation.y"];
相關文章
相關標籤/搜索