日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS CALayer

發布時間:2025/4/16 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS CALayer 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘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)錨點 (xy的范圍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;//圓角是根據當前圖形寬度來設置

}


@end


轉載于:https://my.oschina.net/u/2499773/blog/549405

總結

以上是生活随笔為你收集整理的IOS CALayer的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。