@@ -0,0 +1,83 @@
//
// PickImageViewController.m
// MyTestForCAShapeLayer
//
// Created by 酷酷的1xd on 16/2/17.
// Copyright © 2016年 酷酷的1xd. All rights reserved.
//
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#import "PickImageViewController.h"

@interface PickImageViewController ()<UIImagePickerControllerDelegate>

@end

@implementation PickImageViewController{
UIAlertController *alertVC;

}

- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
[btn setBackgroundColor:[UIColor blueColor]];
[btn setTitle:@"选择图片" forState:UIControlStateNormal];
btn.center = CGPointMake(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
[btn addTarget:self action:@selector(selectImg) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
// Do any additional setup after loading the view.
alertVC = [UIAlertController alertControllerWithTitle:@"My Alert"
message:@"This is an alert."
preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"take_photo" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
UIAlertAction* defaultAction2 = [UIAlertAction actionWithTitle:@"selec_photo" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];

[alertVC addAction:defaultAction];
[alertVC addAction:defaultAction2];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)selectImg{
[self presentViewController:alertVC animated:YES completion:nil];
}

- (void)takePhoto{
UIImagePickerController *con = [[UIImagePickerController alloc]init];
con.delegate = self;
con.sourceType = UIImagePickerControllerSourceTypeCamera;
[self.navigationController pushViewController:con animated:YES];
}

- (void)selectPhoto{
UIImagePickerController *con = [[UIImagePickerController alloc]init];
con.delegate = self;
con.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self.navigationController pushViewController:con animated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
[self.navigationController popViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
@@ -0,0 +1,15 @@
//
// ViewController.h
// MyTestForCAShapeLayer
//
// Created by 酷酷的1xd on 16/2/15.
// Copyright © 2016年 酷酷的1xd. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end

@@ -0,0 +1,294 @@
//
// ViewController.m
// MyTestForCAShapeLayer
//
// Created by 酷酷的1xd on 16/2/15.
// Copyright © 2016年 酷酷的1xd. All rights reserved.
//
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

#import "ViewController.h"
#import "PickImageViewController.h"
#import "XdEditableView.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,UIImagePickerControllerDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *tableHeaderView;
@property (nonatomic, strong) PickImageViewController *pickVC;

@end

@implementation ViewController{
UIAlertController *alertVC;
NSString *filePath;
NSData *imgData;
UIView *scrollViewHeader;
CAShapeLayer *subLayer;
CAShapeLayer *subLayer2;
}

- (void)viewDidLoad {
[super viewDidLoad];
XdEditableView *view = [[XdEditableView alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, SCREEN_HEIGHT-20)];
[self.view addSubview:view];

//[self initTableView];
// Do any additional setup after loading the view, typically from a nib.
//[self initBtn];

}

- (void)initBtn{
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
[btn setBackgroundColor:[UIColor blueColor]];
[btn setTitle:@"选择图片" forState:UIControlStateNormal];
btn.center = CGPointMake(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
[btn addTarget:self action:@selector(selectImg) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
// Do any additional setup after loading the view.
alertVC = [UIAlertController alertControllerWithTitle:@"My Alert"
message:@"This is an alert."
preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"打开相机" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(@"打开相机");
[self takePhoto];
}];
UIAlertAction* defaultAction2 = [UIAlertAction actionWithTitle:@"本地相册" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(@"本地相册");
[self LocalPhoto];
}];
[alertVC addAction:defaultAction];
[alertVC addAction:defaultAction2];
}

- (void)initTableView{
_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, SCREEN_HEIGHT-20)];
_tableView.delegate = self;
_tableView.dataSource = self;
//_tableView.tableHeaderView.backgroundColor = [UIColor greenColor];
//_tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, -200, SCREEN_WIDTH, 200)];
//_tableHeaderView.backgroundColor = [UIColor greenColor];
[_tableView addSubview:[self setScrollHeader]];
[self.view addSubview:_tableView];
}

- (UIView *)setScrollHeader{
scrollViewHeader = ({
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, -80, SCREEN_WIDTH, 80)];
view.backgroundColor = [UIColor greenColor];
subLayer = [[CAShapeLayer alloc]init];
UIBezierPath *path = [[UIBezierPath alloc]init];
[path moveToPoint:CGPointMake(0, 0)];
[path addQuadCurveToPoint:CGPointMake(CGRectGetWidth(view.frame), 0) controlPoint:CGPointMake(CGRectGetMidX(view.frame), CGRectGetHeight(view.frame))];
subLayer.path = path.CGPath;
subLayer.strokeColor = [UIColor blueColor].CGColor;
subLayer.fillColor = [UIColor greenColor].CGColor;
subLayer.lineWidth = 2;
[view.layer addSublayer:subLayer];
subLayer2 = [[CAShapeLayer alloc]init];
subLayer2.strokeColor = [UIColor blueColor].CGColor;
subLayer2.lineWidth = 2;
subLayer2.strokeStart = 0.5;
subLayer2.strokeEnd = 0.5;
UIBezierPath *path2 = [[UIBezierPath alloc]init];
[path2 moveToPoint:CGPointMake(0, 75)];
[path2 addLineToPoint:CGPointMake(SCREEN_WIDTH, 75)];
subLayer2.path = path2.CGPath;
[view.layer addSublayer:subLayer2];
view;
});
return scrollViewHeader;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCell alloc]init];
}
return cell;
}

- (void)selectImg{
[self presentViewController:alertVC animated:YES completion:nil];
}

//开始拍照
-(void)takePhoto
{
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//设置拍照后的图片可被编辑
picker.allowsEditing = YES;
picker.sourceType = sourceType;
[self presentModalViewController:picker animated:YES];
}else
{
NSLog(@"模拟其中无法打开照相机,请在真机中使用");
}
}

//打开本地相册
-(void)LocalPhoto
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
//设置选择后的图片可被编辑
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
}

//当选择一张图片后进入这里
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
NSString *imgDataStr;
//当选择的类型是图片
if ([type isEqualToString:@"public.image"])
{
//先把图片转成NSData
UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *data;
if (UIImagePNGRepresentation(image) == nil)
{
data = UIImageJPEGRepresentation(image, 1.0);
}
else
{
data = UIImagePNGRepresentation(image);
}
imgDataStr = [data base64EncodedStringWithOptions:0];
NSLog(imgDataStr);
NSString *imgDataStr2 = [imgDataStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(imgDataStr2);
//图片保存的路径
//这里将图片放在沙盒的documents文件夹中
NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

//文件管理器
NSFileManager *fileManager = [NSFileManager defaultManager];

//把刚刚图片转换的data对象拷贝至沙盒中 并保存为image.png
[fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
[fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil];

//得到选择后沙盒中图片的完整路径
filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath, @"/image.png"];

//关闭相册界面
[picker dismissModalViewControllerAnimated:YES];

//创建一个选择后图片的小图标放在下方
//类似微薄选择图后的效果
UIImageView *smallimage = [[UIImageView alloc] initWithFrame:
CGRectMake(50, 120, 40, 40)];

smallimage.image = image;
//加在视图中
[self.view addSubview:smallimage];

}
NSString *httpUrl = @"http://apis.baidu.com/idl_baidu/ocrbankcard/ocrbankcard"; //如果出现代理错误,尝试使用https:开头的url
NSString *httpArg = [NSString stringWithFormat:@"fromdevice=pc&clientip=10.10.10.0&languagetype=CHN_ENG&image=%@",imgDataStr];
//
//!!! 具体代码可以参考 http://bbs.apistore.baidu.com/forum.php?mod=viewthread&tid=642&extra= 中的IOS代码
//
[self request: httpUrl withHttpArg: httpArg];

}

-(void)request: (NSString*)httpUrl withHttpArg: (NSString*)HttpArg {
NSURL *url = [NSURL URLWithString: httpUrl];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 10];
[request setHTTPMethod: @"POST"];
[request addValue: @"您自己的apikey" forHTTPHeaderField: @"apikey"];
[request addValue: @"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-Type"];
NSData *data = [HttpArg dataUsingEncoding: NSUTF8StringEncoding];
[request setHTTPBody: data];
[NSURLConnection sendAsynchronousRequest: request
queue: [NSOperationQueue mainQueue]
completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error){
if (error) {
NSLog(@"Httperror: %@%ld", error.localizedDescription, error.code);
} else {
NSInteger responseCode = [(NSHTTPURLResponse *)response statusCode];
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"HttpResponseCode:%ld", responseCode);
NSLog(@"HttpResponseBody %@",responseString);
}
}];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
NSLog(@"您取消了选择图片");
[picker dismissModalViewControllerAnimated:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.y<0) {
[subLayer removeFromSuperlayer];
subLayer = [[CAShapeLayer alloc]init];
UIBezierPath *path = [[UIBezierPath alloc]init];
scrollViewHeader.frame = CGRectMake(0, scrollView.contentOffset.y, SCREEN_WIDTH, -scrollView.contentOffset.y);
[path moveToPoint:CGPointMake(0, 0)];
[path addQuadCurveToPoint:CGPointMake(CGRectGetWidth(scrollViewHeader.frame), 0) controlPoint:CGPointMake(CGRectGetMidX(scrollViewHeader.frame), CGRectGetHeight(scrollViewHeader.frame))];
subLayer.path = path.CGPath;
subLayer.strokeColor = [UIColor blueColor].CGColor;
subLayer.fillColor = [UIColor greenColor].CGColor;
subLayer.lineWidth = 2;
[scrollViewHeader.layer addSublayer:subLayer];
[subLayer2 removeFromSuperlayer];
subLayer2 = [[CAShapeLayer alloc]init];
subLayer2.strokeColor = [UIColor blueColor].CGColor;
subLayer2.lineWidth = 2;
UIBezierPath *path2 = [[UIBezierPath alloc]init];
[path2 moveToPoint:CGPointMake(0, CGRectGetHeight(scrollViewHeader.frame)-2)];
[path2 addLineToPoint:CGPointMake(SCREEN_WIDTH, CGRectGetHeight(scrollViewHeader.frame)-2)];
subLayer2.path = path2.CGPath;
[scrollViewHeader.layer addSublayer:subLayer2];
if (scrollView.contentOffset.y==0) {
subLayer2.strokeStart = 0.5;
subLayer2.strokeEnd = 0.5;
}
else if (scrollView.contentOffset.y<= 0&&scrollView.contentOffset.y>-20) {
subLayer2.strokeStart = 0.5-0.125;
subLayer2.strokeEnd = 0.5+0.125;
}else if (scrollView.contentOffset.y<=-20&&scrollView.contentOffset.y>-40) {
subLayer2.strokeStart = 0.5-0.125*2;
subLayer2.strokeEnd = 0.5+0.125*2;
}else if (scrollView.contentOffset.y<=-40&&scrollView.contentOffset.y>-60) {
subLayer2.strokeStart = 0.5-0.125*3;
subLayer2.strokeEnd = 0.5+0.125*3;
}else if (scrollView.contentOffset.y<=-60) {
subLayer2.strokeStart = 0;
subLayer2.strokeEnd = 1;
}
}
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

}
@end
@@ -0,0 +1,13 @@
//
// XdEditableView.h
// MyTestForCAShapeLayer
//
// Created by 酷酷的1xd on 16/2/29.
// Copyright © 2016年 酷酷的1xd. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface XdEditableView : UIView

@end
@@ -0,0 +1,201 @@
//
// XdEditableView.m
// MyTestForCAShapeLayer
//
// Created by 酷酷的1xd on 16/2/29.
// Copyright © 2016年 酷酷的1xd. All rights reserved.
//

#import "XdEditableView.h"

@implementation XdEditableView{
UIBezierPath *path;
UIView *editView;
CGPoint pointTopLeft;
CGPoint pointTopRight;
CGPoint pointBottomLeft;
CGPoint pointBottomRight;
UIView *viewTopLeft;
UIView *viewTopRight;
UIView *viewBottomLeft;
UIView *viewBottomRight;
CAShapeLayer *caLayer;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/

- (void)drawRect:(CGRect)rect{
[super drawRect:rect];
if (!path) {
path = [UIBezierPath bezierPath];
}
// UIColor *strokeColor = [UIColor greenColor];
// [strokeColor setStroke];
// [path setLineWidth:3.0];
// [path moveToPoint:pointTopLeft];
// [path addLineToPoint:pointTopRight];
// [path addLineToPoint:pointBottomRight];
// [path addLineToPoint:pointBottomLeft];
// [path addLineToPoint:pointTopLeft];
// [path stroke];
}

- (instancetype )initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self initFourPoints];
[self initEditView];
[self addFourPointViews];
return self;
}
return nil;
}

- (void)initEditView{
editView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.frame)/10, CGRectGetWidth(self.frame)/10, CGRectGetWidth(self.frame)*8/10, CGRectGetHeight(self.frame)*8/10)];
//editView.backgroundColor = [UIColor redColor];
//editView.layer.masksToBounds = YES;
[self addSubview:editView];
caLayer = [[CAShapeLayer alloc]init];
UIBezierPath *localPath = [UIBezierPath bezierPath];
[localPath moveToPoint:CGPointMake(pointTopLeft.x-CGRectGetWidth(self.frame)/10, pointTopLeft.y-CGRectGetWidth(self.frame)/10)];
[localPath addLineToPoint:CGPointMake(pointTopRight.x-CGRectGetWidth(self.frame)/10, pointTopRight.y-CGRectGetWidth(self.frame)/10)];
[localPath addLineToPoint:CGPointMake(pointBottomRight.x-CGRectGetWidth(self.frame)/10, pointBottomRight.y-CGRectGetWidth(self.frame)/10)];
[localPath addLineToPoint:CGPointMake(pointBottomLeft.x-CGRectGetWidth(self.frame)/10, pointBottomLeft.y-CGRectGetWidth(self.frame)/10)];
[localPath addLineToPoint:CGPointMake(pointTopLeft.x-CGRectGetWidth(self.frame)/10, pointTopLeft.y-CGRectGetWidth(self.frame)/10)];
caLayer.path = localPath.CGPath;
caLayer.strokeColor = [UIColor yellowColor].CGColor;
caLayer.fillColor = [UIColor colorWithPatternImage:[self scaleImgToFitEdittingView:[UIImage imageNamed:@"a.jpg"]]].CGColor;
caLayer.lineJoin = kCALineJoinBevel;
caLayer.lineWidth = 1;
[editView.layer addSublayer:caLayer];
}

- (void)initFourPoints{
pointTopLeft = CGPointMake(CGRectGetWidth(self.frame)/10, CGRectGetWidth(self.frame)/10);
pointTopRight = CGPointMake(CGRectGetWidth(self.frame)*9/10, CGRectGetWidth(self.frame)/10);
pointBottomLeft = CGPointMake(CGRectGetWidth(self.frame)/10, CGRectGetWidth(self.frame)*9/10);
pointBottomRight = CGPointMake(CGRectGetWidth(self.frame)*9/10, CGRectGetWidth(self.frame)*9/10);
}

- (void)addFourPointViews{
viewTopLeft = ({
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
view.center = pointTopLeft;
view.tag = 1;
[view addGestureRecognizer:[self getPanGestureRecognizer]];
view.backgroundColor = [UIColor clearColor];
view.layer.masksToBounds = YES;
view.layer.cornerRadius = CGRectGetWidth(view.frame)/2;
view;
});
viewTopRight = ({
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
view.center = pointTopRight;
view.tag = 2;
[view addGestureRecognizer:[self getPanGestureRecognizer]];
view.backgroundColor = [UIColor clearColor];
view.layer.masksToBounds = YES;
view.layer.cornerRadius = CGRectGetWidth(view.frame)/2;
view;
});
viewBottomLeft = ({
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
view.center = pointBottomLeft;
view.tag = 4;
[view addGestureRecognizer:[self getPanGestureRecognizer]];
view.backgroundColor = [UIColor clearColor];
view.layer.masksToBounds = YES;
view.layer.cornerRadius = CGRectGetWidth(view.frame)/2;
view;
});
viewBottomRight = ({
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
view.center = pointBottomRight;
view.tag = 3;
[view addGestureRecognizer:[self getPanGestureRecognizer]];
view.backgroundColor = [UIColor clearColor];
view.layer.masksToBounds = YES;
view.layer.cornerRadius = CGRectGetWidth(view.frame)/2;
view;
});
if (self) {
[self addSubview:viewTopLeft];
[self addSubview:viewTopRight];
[self addSubview:viewBottomLeft];
[self addSubview:viewBottomRight];
}
}

- (void)drawEditableRect{
// [caLayer removeFromSuperlayer];
// caLayer = [[CAShapeLayer alloc]init];
UIBezierPath *localPath = [UIBezierPath bezierPath];
[localPath moveToPoint:CGPointMake(pointTopLeft.x-CGRectGetWidth(self.frame)/10, pointTopLeft.y-CGRectGetWidth(self.frame)/10)];
[localPath addLineToPoint:CGPointMake(pointTopRight.x-CGRectGetWidth(self.frame)/10, pointTopRight.y-CGRectGetWidth(self.frame)/10)];
[localPath addLineToPoint:CGPointMake(pointBottomRight.x-CGRectGetWidth(self.frame)/10, pointBottomRight.y-CGRectGetWidth(self.frame)/10)];
[localPath addLineToPoint:CGPointMake(pointBottomLeft.x-CGRectGetWidth(self.frame)/10, pointBottomLeft.y-CGRectGetWidth(self.frame)/10)];
[localPath addLineToPoint:CGPointMake(pointTopLeft.x-CGRectGetWidth(self.frame)/10, pointTopLeft.y-CGRectGetWidth(self.frame)/10)];
caLayer.path = localPath.CGPath;
// caLayer.strokeColor = [UIColor yellowColor].CGColor;
// caLayer.fillColor = [UIColor colorWithPatternImage:[self scaleImgToFitEdittingView:[UIImage imageNamed:@"a.jpg"]]].CGColor;
// caLayer.lineWidth = 5;
// [editView.layer addSublayer:caLayer];
//[self setNeedsDisplay];
}

- (UIPanGestureRecognizer *)getPanGestureRecognizer{
UIPanGestureRecognizer *panGes = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGesFunc:)];
return panGes;
}

- (void)panGesFunc:(UIPanGestureRecognizer *)panGes{
long tag = [panGes.view tag];
UIView *tempView = panGes.view;
CGPoint point = [panGes translationInView:self];
tempView.center = CGPointMake(tempView.center.x+point.x, tempView.center.y+point.y);
switch (tag) {
case 1:
{
pointTopLeft = tempView.center;
}
break;
case 2:
{
pointTopRight = tempView.center;
}
break;
case 3:
{
pointBottomRight = tempView.center;
}
break;
case 4:
{
pointBottomLeft = tempView.center;
}
break;

default:
break;
}
[panGes setTranslation:CGPointMake(0, 0) inView:self];
[self drawEditableRect];
}

- (UIImage *)scaleImgToFitEdittingView:(UIImage *)img{
UIGraphicsBeginImageContext(CGSizeMake(CGRectGetWidth(self.frame), CGRectGetWidth(self.frame)));
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, 0, CGRectGetWidth(self.frame));
CGContextScaleCTM(ctx, 1, -1);
[img drawInRect:CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetWidth(self.frame))];

UIImage *temp = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return temp;
}
@end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,16 @@
//
// main.m
// MyTestForCAShapeLayer
//
// Created by 酷酷的1xd on 16/2/15.
// Copyright © 2016年 酷酷的1xd. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
@@ -0,0 +1,39 @@
//
// MyTestForCAShapeLayerTests.m
// MyTestForCAShapeLayerTests
//
// Created by 酷酷的1xd on 16/2/15.
// Copyright © 2016年 酷酷的1xd. All rights reserved.
//

#import <XCTest/XCTest.h>

@interface MyTestForCAShapeLayerTests : XCTestCase

@end

@implementation MyTestForCAShapeLayerTests

- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testExample {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
}

@end
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
@@ -0,0 +1,40 @@
//
// MyTestForCAShapeLayerUITests.m
// MyTestForCAShapeLayerUITests
//
// Created by 酷酷的1xd on 16/2/15.
// Copyright © 2016年 酷酷的1xd. All rights reserved.
//

#import <XCTest/XCTest.h>

@interface MyTestForCAShapeLayerUITests : XCTestCase

@end

@implementation MyTestForCAShapeLayerUITests

- (void)setUp {
[super setUp];

// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
self.continueAfterFailure = NO;
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
[[[XCUIApplication alloc] init] launch];

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testExample {
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

@end