IOS CALayer
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
//
//? ViewController.m
//? CALayer12.22
//
//? Created by dc008 on 15/12/22.
//? Copyright ? 2015年 崔曉宇. All rights reserved.
//
#import "ViewController.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
#define LayerWidth 50
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
? ? [super viewDidLoad];
?? ?
? ? CALayer *layer = [[CALayer alloc]init];
? ? //設置寬高
? ? layer.bounds = CGRectMake(0, 0, LayerWidth, LayerWidth);
? ? layer.position = CGPointMake(WIDTH/2.0, HEIGHT/2.0);
? ? layer.backgroundColor = [UIColor colorWithRed:0.3 green:0.2 blue:0.7 alpha:0.7].CGColor;
? ? [self.view.layer addSublayer:layer];
?? ?
? ? //設置圓角
? ? layer.cornerRadius = LayerWidth/ 2;
? ? //設置陰影
? ? layer.shadowColor = [UIColor grayColor].CGColor;
? ? //陰影偏移量
? ? layer.shadowOffset = CGSizeMake(2, 2);
? ? //陰影透明度(0-1),默認是0
? ? layer.shadowOpacity = 0.9;
? ? NSLog(@"CALayer內存地址:%@",layer);
? ? //(mao)錨點 (x和y的范圍0-1)
//? ? layer.anchorPoint = CGPointMake(1, 1);
?? ?
}
- (void)didReceiveMemoryWarning {
? ? [super didReceiveMemoryWarning];
? ? // Dispose of any resources that can be recreated.
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
? ? //獲取點擊位置
? ? UITouch *touch = [touches anyObject];
? ? NSLog(@"點擊的位置是:%@",NSStringFromCGPoint([touch locationInView: self.view]));
?? ?
? ? //獲取layer
? ? NSLog(@"%@",self.view.layer.sublayers);
? ? CALayer *layer = [[CALayer alloc]init];
? ? layer = self.view.layer.sublayers[2];
? ? layer.position = [touch locationInView:self.view];
? ? //放大
? ? CGFloat width = layer.bounds.size.width;
? ? if (width == LayerWidth) {
? ? ? ? width = LayerWidth * 4;
? ? }
? ? else {
? ? ? ? width = LayerWidth; ? ? ?
? ? }
? ? layer.bounds = CGRectMake(0, 0, width, width);
? ? layer.cornerRadius = width/2;//圓角是根據(jù)當前圖形寬度來設置
}
@end
轉載于:https://my.oschina.net/u/2499773/blog/549405
總結
以上是生活随笔為你收集整理的IOS CALayer的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2015第53周二
- 下一篇: 单片机温度控制系统DS18B20