- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 150 , 200)];
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 150 , 200)];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(100, 100,150 , 200)];
// UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 150 , 200)];
// view3.backgroundColor = [UIColor blueColor];
view1.backgroundColor = [UIColor redColor];
view2.backgroundColor = [UIColor greenColor];
view.backgroundColor = [[UIColor redColor]colorWithAlphaComponent:0.3];//设置颜色和透明度
view.layer.backgroundColor = [[UIColor grayColor]colorWithAlphaComponent:0.5].CGColor;
// center:描述当前视图的中心点在其父视图中的位置。
// view.center = CGPointMake(200, 200);
/* frame 的bounds属性和anchor point属性都是针对一个frame自身而言的,而frame 的position属性,是一个frame相对于它的parent frame而言的,它指定了这个frame在它的parent frame坐标系中相对于parent frame bounds左上角的位置。*/
// view.layer.position = CGPointMake(320/2, 480/2);
/* frame的大小是由bounds属性决定的,由bounds框框起来的范围是一个frame真正可以显示出来的范围 */
// view.layer.bounds = CGRectMake(0, 0, 100, 100);
/* bounds (0,0,100,100) --> (0,0,200,200) 本地坐标系统原点往左往上分别50。center不变,效果是按照中心放大view bounds(0,0,100,100) --> (100,100,100,100) 本地坐标系统原点往左往上分别100。center不变,没有可视效果变化(但是本地坐标系统的原点已经改变) 结论: bounds属性影响到本地坐标系统的原点。需要注意
*/
// view.bounds = CGRectMake(100,100, 300, 300);
/*anchorPoint属性,值域是0~1,是个比例值,这个图形是各种图形变换的坐标原点同时会更改layer的position的位置,它的缺省值是(0.5,0.5),即在layer的中央
anchorpoint可以在bounds范围内移动,它的值从(0.0,0.0)到(1.0,1.0)默认值为(0.0,0.0),也就是bounds的左上角点 anchor point点是一个frame在旋转、平移、缩放时的参考点,frame在做旋转、缩放、平移等变换时就是以anchor point点为中心点。 center是父视图
*/
view.layer.anchorPoint = CGPointMake(0.5f,0.5f);//
view1.layer.anchorPoint = CGPointMake(0.f,0.f);//绿色 向上
view2.layer.anchorPoint = CGPointMake(1.0f,1.0f);//红色向下
// view3.layer.anchorPoint = CGPointMake(1.0f,0.f);
NSLog(@"view %f,%f,%f,%f",view.frame.origin.x,view.frame.origin.y,view.frame.size.width,view.frame.size.height);
NSLog(@"layer %f,%f,%f,%f",view.layer.frame.origin.x,view.layer.frame.origin.y,view.frame.size.width,view.frame.size.height);
NSLog(@"anchorPoint %f,%f",view2.layer.anchorPoint.x,view2.layer.anchorPoint.y);
NSLog(@"view layer bounds %f , %f , %f, %f",view1.layer.bounds.origin.x,view1.layer.bounds.origin.y,view1.layer.bounds.size.width,view1.layer.bounds.size.height);
NSLog(@"view bounds %f , %f , %f, %f",view2.bounds.origin.x,view2.bounds.origin.y,view2.bounds.size.width,view2.bounds.size.height);
NSLog(@"view position %f ,%f",view2.layer.position.x,view2.layer.position.y);
// view.layer.cornerRadius = 50;//根据修改的值的大小其位置会改变其 图层的边角为圆型
// view.layer.shadowOffset = CGSizeMake(100, 100);
//
// view.layer.shadowColor = [UIColor redColor].CGColor;
[self.view addSubview:view1];
[self.view addSubview:view2];
[self.view addSubview:view];
// [self.view addSubview:view3];
[view.layer setNeedsDisplay];