CALayer实现点击屏幕放大或者缩小的一个圆

时间:2021-10-02 08:15:02
#import "ViewController.h"
#define WIDTH 50
@interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
[self drawMyLayer];
}
-(void)drawMyLayer
{
CGSize size=[UIScreen mainScreen].bounds.size; CALayer *layer=[[CALayer alloc]init];
layer.backgroundColor=[UIColor colorWithRed: green:/255.0 blue:1.0 alpha:1.0].CGColor;
layer.position=CGPointMake(size.width/, size.height/);
layer.bounds=CGRectMake(, , WIDTH, WIDTH);
layer.cornerRadius=WIDTH/;
layer.shadowColor=[UIColor grayColor].CGColor;
layer.shadowOffset=CGSizeMake(, );
layer.shadowOpacity=0.9;
[self.view.layer addSublayer:layer]; }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; }
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[touches anyObject];
CALayer *layer=self.view.layer.sublayers[];
CGFloat width=layer.bounds.size.width;
if (width==WIDTH) {
width=WIDTH *;
}
else
{
width=WIDTH;
}
layer.bounds=CGRectMake(, , width, width);
layer.position=[touch locationInView:self.view];
layer.cornerRadius=width/;
[self.view.layer addSublayer:layer];
}
@end

CALayer实现点击屏幕放大或者缩小的一个圆