-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YangQi
committed
Dec 12, 2018
1 parent
79ebd18
commit c6b540d
Showing
8 changed files
with
229 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+2.62 KB
(110%)
...Card/AmazingCard.xcworkspace/xcuserdata/yangqi.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// ACEditViewController+Brush.h | ||
// AmazingCard | ||
// | ||
// Created by 杨琦 on 2018/12/11. | ||
// Copyright © 2018 A.C. All rights reserved. | ||
// | ||
|
||
#import "ACEditViewController.h" | ||
|
||
@interface ACEditViewController (Brush) | ||
|
||
- (void)brush; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// ACEditViewController+Brush.m | ||
// AmazingCard | ||
// | ||
// Created by 杨琦 on 2018/12/11. | ||
// Copyright © 2018 A.C. All rights reserved. | ||
// | ||
|
||
#import "ACEditViewController+Brush.h" | ||
|
||
@implementation ACEditViewController (Brush) | ||
|
||
- (void)brush { | ||
|
||
} | ||
|
||
@end |
15 changes: 15 additions & 0 deletions
15
AmazingCard/AmazingCard/Edit/ACEditViewController+Circle.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// ACEditViewController+Circle.h | ||
// AmazingCard | ||
// | ||
// Created by 杨琦 on 2018/12/11. | ||
// Copyright © 2018 A.C. All rights reserved. | ||
// | ||
|
||
#import "ACEditViewController.h" | ||
|
||
@interface ACEditViewController (Circle) | ||
|
||
- (void)circle; | ||
|
||
@end |
159 changes: 159 additions & 0 deletions
159
AmazingCard/AmazingCard/Edit/ACEditViewController+Circle.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// | ||
// ACEditViewController+Circle.m | ||
// AmazingCard | ||
// | ||
// Created by 杨琦 on 2018/12/11. | ||
// Copyright © 2018 A.C. All rights reserved. | ||
// | ||
|
||
#import "ACEditViewController+Circle.h" | ||
|
||
@implementation ACEditViewController (Circle) | ||
|
||
- (void)circle { | ||
|
||
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"amazingCard"]]; | ||
self.imageView.contentMode = UIViewContentModeScaleAspectFit; | ||
self.imageView.userInteractionEnabled = YES; | ||
[self.view addSubview:self.imageView]; | ||
|
||
self.imageView.frame = self.view.bounds; | ||
|
||
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; | ||
[self.imageView addGestureRecognizer:pan]; | ||
|
||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; | ||
[self.imageView addGestureRecognizer:tap]; | ||
|
||
UIView *clipV = [[UIView alloc] init]; | ||
clipV.backgroundColor = [UIColor redColor]; | ||
clipV.alpha = 0.5; | ||
[self.view addSubview:clipV]; | ||
self.clipView = clipV; | ||
self.clipView.hidden = YES; | ||
self.clipView.frame = CGRectMake(self.view.center.x, self.view.center.y, 25, 25); | ||
UIPanGestureRecognizer *clipViewPan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; | ||
[self.clipView addGestureRecognizer:clipViewPan]; | ||
|
||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(barButtonItem:)]; | ||
} | ||
|
||
- (void)tap:(UIGestureRecognizer *)tap { | ||
if (CGPointEqualToPoint(self.startP, CGPointZero)) { | ||
CGPoint p = [tap locationInView:self.imageView]; | ||
NSLog(@"x = %f, y = %f", p.x, p.y); | ||
self.clipView.frame = CGRectMake(0, 0, offset*2, offset*2); | ||
self.clipView.center = p; | ||
self.clipView.hidden = NO; | ||
self.startP = self.clipView.frame.origin; | ||
} | ||
} | ||
|
||
- (void)pan:(UIPanGestureRecognizer *)pan { | ||
|
||
CGPoint p = [pan locationInView:self.imageView]; | ||
NSLog(@"x = %f, y = %f", p.x, p.y); | ||
|
||
//添加拖拽 | ||
if ([pan.view isEqual:self.clipView]) { | ||
// if (self.clipView.frame.size.width > offset*2 | ||
// && self.clipView.frame.size.height > offset*2) | ||
// { | ||
// //超出范围不可拖拽 | ||
// CGRect frame = CGRectMake(self.clipView.frame.origin.x + offset/2, self.clipView.frame.origin.y+offset/2, self.clipView.frame.size.width-offset, self.clipView.frame.size.height-offset); | ||
// if (!CGRectContainsPoint(frame, p)) { | ||
// return; | ||
// } | ||
// } | ||
|
||
CGPoint translation = [pan translationInView:pan.view.superview]; | ||
CGPoint finalCenter = CGPointMake(pan.view.center.x + translation.x, pan.view.center.y + translation.y); | ||
pan.view.center = finalCenter; | ||
self.startP = self.clipView.frame.origin; | ||
self.curP = CGPointMake(self.startP.x + self.clipView.frame.size.width, self.startP.y + self.clipView.frame.size.height); | ||
[pan setTranslation:CGPointMake(0, 0) inView:pan.view]; | ||
return; | ||
} | ||
|
||
//startP是否为空(第一次) | ||
if (CGPointEqualToPoint(self.startP, CGPointZero)) { | ||
self.startP = p; | ||
self.startP = CGPointMake(p.x-offset, p.y-offset); | ||
self.clipView.frame = CGRectMake(self.startP.x, self.startP.y, offset*2, offset*2); | ||
|
||
} else { | ||
if (p.x < self.clipView.center.x) { | ||
if (p.y > self.clipView.center.y) { | ||
self.startP = CGPointMake(p.x, self.startP.y); | ||
self.curP = CGPointMake(self.curP.x, p.y); | ||
CGFloat offsetX = self.curP.x - self.startP.x; | ||
CGFloat offsetY = self.curP.y - self.startP.y; | ||
self.clipView.frame = CGRectMake(self.startP.x, self.startP.y, offsetX, offsetY); | ||
} else { | ||
self.startP = p; | ||
CGFloat offsetX = self.curP.x - self.startP.x; | ||
CGFloat offsetY = self.curP.y - self.startP.y; | ||
self.clipView.frame = CGRectMake(self.startP.x, self.startP.y, offsetX, offsetY); | ||
} | ||
} else { | ||
if (p.y < self.clipView.center.y) { | ||
self.startP = CGPointMake(self.startP.x, p.y); | ||
self.curP = CGPointMake(p.x, self.curP.y); | ||
CGFloat offsetX = self.curP.x - self.startP.x; | ||
CGFloat offsetY = self.curP.y - self.startP.y; | ||
self.clipView.frame = CGRectMake(self.startP.x, self.startP.y, offsetX, offsetY); | ||
} else { | ||
self.curP = p; | ||
CGFloat offsetX = self.curP.x - self.startP.x; | ||
CGFloat offsetY = self.curP.y - self.startP.y; | ||
self.clipView.frame = CGRectMake(self.startP.x, self.startP.y, offsetX, offsetY); | ||
} | ||
} | ||
} | ||
self.clipView.hidden = NO; | ||
} | ||
|
||
- (void)barButtonItem:(UIBarButtonItem *)barButton { | ||
CGRect clipViewframe = self.clipView.frame; | ||
self.clipView.hidden = YES; | ||
self.startP = CGPointZero; | ||
self.curP = CGPointZero; | ||
|
||
CGFloat imageCurWidth = self.view.bounds.size.width; | ||
CGFloat imageCurHeight = imageCurWidth * self.imageView.image.size.height /self.imageView.image.size.width; | ||
|
||
CGFloat curClipY = clipViewframe.origin.y - (self.view.bounds.size.height - imageCurHeight) / 2.0; | ||
CGFloat curClipX = clipViewframe.origin.x; | ||
|
||
CGSize size = self.imageView.image.size; | ||
CGSize viewSize = self.view.frame.size; | ||
CGFloat scale = viewSize.width / size.width * size.height < viewSize.height ? viewSize.width / size.width : viewSize.height / size.height; | ||
CGFloat clipY = curClipY / scale; | ||
CGFloat clipX = curClipX / scale; | ||
CGFloat clipW = clipViewframe.size.width / scale; | ||
CGFloat clipH = clipViewframe.size.height / scale; | ||
CGRect clipFrame = CGRectMake(clipX, clipY, clipW, clipH); | ||
|
||
UIImage *image = [self getImageFromImage:self.imageView.image rect:clipFrame]; | ||
self.imageView.image = image; | ||
} | ||
|
||
-(UIImage *)getImageFromImage:(UIImage *)image rect:(CGRect)rect { | ||
|
||
//大图bigImage | ||
//定义myImageRect,截图的区域 | ||
CGRect myImageRect = rect; | ||
CGImageRef imageRef = image.CGImage; | ||
CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect); | ||
CGSize size = image.size; | ||
UIGraphicsBeginImageContext(size); | ||
CGContextRef context = UIGraphicsGetCurrentContext(); | ||
CGContextDrawImage(context, myImageRect, subImageRef); | ||
UIImage* smallImage = [UIImage imageWithCGImage:subImageRef]; | ||
UIGraphicsEndImageContext(); | ||
|
||
return smallImage; | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.