Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1064e16
Add property to change reset button color and slider tint color
caotrido Aug 24, 2015
ba2e9ac
Merge pull request #17 from caotrido/master
itouch2 Aug 24, 2015
80c877d
minor changes
itouch2 Aug 24, 2015
54bcbea
Fixed width and height calculation when rotate to any angle.
wowmendezz Oct 8, 2015
3aa4734
Merge pull request #19 from SergeyZalozniy/master
itouch2 May 19, 2016
86ee393
minor changes
itouch2 May 19, 2016
a33a66c
supports max rotation angle
itouch2 May 19, 2016
b6ce48a
modify podspec
itouch2 May 20, 2016
97577e0
Merge pull request #22 from itouch2/dev
itouch2 May 20, 2016
f4b36ef
Update README.md
itouch2 May 25, 2016
6d9234c
reset the sliderValue
AppriaTT Jun 13, 2016
40568b6
修复color space读取不到的问题
AppriaTT Aug 31, 2016
23aacf0
Update xcschememanagement.plist
AppriaTT Aug 31, 2016
b919dbd
Update xcschememanagement.plist
AppriaTT Aug 31, 2016
00f0112
Merge pull request #26 from AppriaTT/master
itouch2 Oct 12, 2016
02c4311
Delete xcschememanagement
itouch2 Oct 12, 2016
ac0c768
Change Travis.yml
itouch2 Oct 12, 2016
5081eea
Reset PhotoTweaks.xcscheme
itouch2 Oct 12, 2016
63579c7
Change Travis
itouch2 Oct 12, 2016
4e4dafe
Add NSPhotoLibraryUsageDescription for iOS 10
itouch2 Oct 12, 2016
54e5c47
Change Travis use iphonesimulator9.3
itouch2 Oct 12, 2016
2af685f
Change pod 1.0.3 -> 1.0.4
itouch2 Oct 12, 2016
3692fe5
Update README.md
itouch2 Oct 12, 2016
d8f39de
Using UIImageWriteToSavedPhotosAlbum for saving image to local
NikhilManapure Jun 15, 2017
e62ba4b
Reset should not make CropView's frame as same as ScrollView
NikhilManapure Jun 15, 2017
47b167f
Deleted the commented Code
NikhilManapure Jun 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ language: objective-c
xcode_project: PhotoTweaks.xcodeproj
xcode_scheme: PhotoTweaks
xcode_sdk:
- iphonesimulator8.1
- iphonesimulator9.3
4 changes: 2 additions & 2 deletions PhotoTweaks.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |spec|
spec.name = 'PhotoTweaks'
spec.version = '1.0.2'
spec.version = '1.0.4'
spec.license = 'MIT'
spec.homepage = 'https://github.com/itouch2/PhotoTweaks'
spec.authors = {'Tu You' => 'yoututouch@gmail.com'}
spec.summary = 'Drag, Rotate, Scale and Crop.'
spec.source = {:git => 'https://github.com/itouch2/PhotoTweaks.git', :tag => '1.0.2'}
spec.source = {:git => 'https://github.com/itouch2/PhotoTweaks.git', :tag => '1.0.4'}
spec.source_files = 'PhotoTweaks/PhotoTweaks/*.{h,m}'
spec.framework = 'Foundation', 'CoreGraphics', 'UIKit'
spec.requires_arc = true
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions PhotoTweaks/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
PhotoTweaksViewController *photoTweaksViewController = [[PhotoTweaksViewController alloc] initWithImage:image];
photoTweaksViewController.delegate = self;
photoTweaksViewController.autoSaveToLibray = YES;
photoTweaksViewController.maxRotationAngle = M_PI_4;
[picker pushViewController:photoTweaksViewController animated:YES];
}

Expand Down
2 changes: 2 additions & 0 deletions PhotoTweaks/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSPhotoLibraryUsageDescription</key>
<string></string>
</dict>
</plist>
22 changes: 17 additions & 5 deletions PhotoTweaks/PhotoTweaks/PhotoTweakView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import <UIKit/UIKit.h>

extern const CGFloat kMaxRotationAngle;

@class CropView;

@interface PhotoContentView : UIView
Expand All @@ -29,12 +31,22 @@

@interface PhotoTweakView : UIView

@property (assign, nonatomic) CGFloat angle;
@property (strong, nonatomic) PhotoContentView *photoContentView;
@property (assign, nonatomic) CGPoint photoContentOffset;
@property (strong, nonatomic) CropView *cropView;
@property (nonatomic, assign, readonly) CGFloat angle;
@property (nonatomic, assign, readonly) CGPoint photoContentOffset;

@property (nonatomic, strong, readonly) CropView *cropView;
@property (nonatomic, strong, readonly) PhotoContentView *photoContentView;
@property (nonatomic, strong, readonly) UISlider *slider;
@property (nonatomic, strong, readonly) UIButton *resetBtn;


- (instancetype)initWithFrame:(CGRect)frame
image:(UIImage *)image
maxRotationAngle:(CGFloat)maxRotationAngle;

- (instancetype)initWithFrame:(CGRect)frame
image:(UIImage *)image;

- (instancetype)initWithFrame:(CGRect)frame image:(UIImage *)image;
- (CGPoint)photoTranslation;

@end
42 changes: 26 additions & 16 deletions PhotoTweaks/PhotoTweaks/PhotoTweakView.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#import "UIColor+Tweak.h"
#import <math.h>

static const int kCropLines = 2;
static const int kGridLines = 9;
const CGFloat kMaxRotationAngle = 0.5;
static const NSUInteger kCropLines = 2;
static const NSUInteger kGridLines = 9;

static const CGFloat kCropViewHotArea = 16;
static const CGFloat kMinimumCropArea = 60;
Expand Down Expand Up @@ -55,7 +56,7 @@ - (void)layoutSubviews

@interface PhotoScrollView : UIScrollView

@property (strong, nonatomic) PhotoContentView *photoContentView;
@property (nonatomic, strong) PhotoContentView *photoContentView;

@end

Expand Down Expand Up @@ -429,11 +430,13 @@ - (void)showLines:(NSArray *)lines
@interface PhotoTweakView () <UIScrollViewDelegate, CropViewDelegate>

@property (nonatomic, strong) PhotoScrollView *scrollView;
@property (nonatomic, strong) CropView *cropView;

@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) UISlider *slider;
@property (nonatomic, strong) UIButton *resetBtn;
@property (nonatomic, assign) CGSize originalSize;
@property (nonatomic, assign) CGFloat angle;

@property (nonatomic, assign) BOOL manualZoomed;

Expand All @@ -447,22 +450,26 @@ @interface PhotoTweakView () <UIScrollViewDelegate, CropViewDelegate>
@property (nonatomic, assign) CGSize maximumCanvasSize;
@property (nonatomic, assign) CGFloat centerY;
@property (nonatomic, assign) CGPoint originalPoint;
@property (nonatomic, assign) CGFloat maxRotationAngle;

@end

@implementation PhotoTweakView

- (instancetype)initWithFrame:(CGRect)frame image:(UIImage *)image
- (instancetype)initWithFrame:(CGRect)frame
image:(UIImage *)image
maxRotationAngle:(CGFloat)maxRotationAngle
{
if (self = [super init]) {

self.frame = frame;

_image = image;
_maxRotationAngle = maxRotationAngle;

// scale the image
_maximumCanvasSize = CGSizeMake(kMaximumCanvasWidthRatio * self.frame.size.width,
kMaximumCanvasHeightRatio * self.frame.size.height - kCanvasHeaderHeigth);
kMaximumCanvasHeightRatio * self.frame.size.height - kCanvasHeaderHeigth);

CGFloat scaleX = image.size.width / self.maximumCanvasSize.width;
CGFloat scaleY = image.size.height / self.maximumCanvasSize.height;
Expand Down Expand Up @@ -520,13 +527,12 @@ - (instancetype)initWithFrame:(CGRect)frame image:(UIImage *)image
[self addSubview:_rightMask];
[self updateMasks:NO];

_slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, 240, 20)];
_slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, 260, 20)];
_slider.center = CGPointMake(CGRectGetWidth(self.bounds) / 2, CGRectGetHeight(self.bounds) - 135);
_slider.minimumValue = 0.0f;
_slider.maximumValue = 1.0f;
_slider.minimumValue = -self.maxRotationAngle;
_slider.maximumValue = self.maxRotationAngle;
[_slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[_slider addTarget:self action:@selector(sliderTouchEnded:) forControlEvents:UIControlEventTouchUpInside];
_slider.value = 0.5;
[self addSubview:_slider];

_resetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
Expand All @@ -544,6 +550,11 @@ - (instancetype)initWithFrame:(CGRect)frame image:(UIImage *)image
return self;
}

- (instancetype)initWithFrame:(CGRect)frame image:(UIImage *)image
{
return [self initWithFrame:frame image:image maxRotationAngle:kMaxRotationAngle];
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (CGRectContainsPoint(self.slider.frame, point)) {
Expand Down Expand Up @@ -583,8 +594,8 @@ - (void)cropEnded:(CropView *)cropView
CGRect newCropBounds = CGRectMake(0, 0, scale * cropView.frame.size.width, scale * cropView.frame.size.height);

// calculate the new bounds of scroll view
CGFloat width = cos(fabs(self.angle)) * newCropBounds.size.width + sin(fabs(self.angle)) * newCropBounds.size.height;
CGFloat height = sin(fabs(self.angle)) * newCropBounds.size.width + cos(fabs(self.angle)) * newCropBounds.size.height;
CGFloat width = fabs(cos(self.angle)) * newCropBounds.size.width + fabs(sin(self.angle)) * newCropBounds.size.height;
CGFloat height = fabs(sin(self.angle)) * newCropBounds.size.width + fabs(cos(self.angle)) * newCropBounds.size.height;

// calculate the zoom area of scroll view
CGRect scaleFrame = cropView.frame;
Expand Down Expand Up @@ -674,12 +685,12 @@ - (void)sliderValueChanged:(id)sender
[self.cropView updateGridLines:NO];

// rotate scroll view
self.angle = self.slider.value - 0.5;
self.angle = self.slider.value;
self.scrollView.transform = CGAffineTransformMakeRotation(self.angle);

// position scroll view
CGFloat width = cos(fabs(self.angle)) * self.cropView.frame.size.width + sin(fabs(self.angle)) * self.cropView.frame.size.height;
CGFloat height = sin(fabs(self.angle)) * self.cropView.frame.size.width + cos(fabs(self.angle)) * self.cropView.frame.size.height;
CGFloat width = fabs(cos(self.angle)) * self.cropView.frame.size.width + fabs(sin(self.angle)) * self.cropView.frame.size.height;
CGFloat height = fabs(sin(self.angle)) * self.cropView.frame.size.width + fabs(cos(self.angle)) * self.cropView.frame.size.height;
CGPoint center = self.scrollView.center;

CGPoint contentOffset = self.scrollView.contentOffset;
Expand Down Expand Up @@ -717,11 +728,10 @@ - (void)resetBtnTapped:(id)sender
self.scrollView.minimumZoomScale = 1;
[self.scrollView setZoomScale:1 animated:NO];

self.cropView.frame = self.scrollView.frame;
self.cropView.center = self.scrollView.center;
[self updateMasks:NO];

[self.slider setValue:0.5 animated:YES];
[self.slider setValue:0 animated:YES];
}];
}

Expand Down
Loading