Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DenTelezhkin committed Jul 27, 2014
1 parent 0b71f42 commit c80f714
Show file tree
Hide file tree
Showing 19 changed files with 1,559 additions and 7 deletions.
28 changes: 21 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control?
#
# Pods/
# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.moved-aside
DerivedData
.idea/
*.hmap
*.xccheckout

#CocoaPods
Pods
Podfile.lock
*.xcworkspace
19 changes: 19 additions & 0 deletions ShapeKit/DimmedView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// RoundDimmedView.h
// GeoTourist
//
// Created by Denys Telezhkin on 23.07.14.
// Copyright (c) 2014 MLSDev. All rights reserved.
//

#import "ShapedView.h"

@interface DimmedView : ShapedView

-(void)makeVisiblePath:(UIBezierPath *)visiblePath
dimmedPath:(UIBezierPath *)dimmedPath;

@property (nonatomic, assign) float opacity;
@property (nonatomic, strong) UIColor * dimmingColor;

@end
52 changes: 52 additions & 0 deletions ShapeKit/DimmedView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// RoundDimmedView.m
// GeoTourist
//
// Created by Denys Telezhkin on 23.07.14.
// Copyright (c) 2014 MLSDev. All rights reserved.
//

#import "DimmedView.h"

@implementation DimmedView

-(void)commonSetup
{
self.opacity = 0.9;
self.dimmingColor = [UIColor blackColor];
}

-(instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
[self commonSetup];
}
return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder])
{
[self commonSetup];
}
return self;
}

-(void)makeVisiblePath:(UIBezierPath *)visiblePath dimmedPath:(UIBezierPath *)dimmedPath
{
[visiblePath setUsesEvenOddFillRule:YES];

[dimmedPath appendPath:visiblePath];
[dimmedPath setUsesEvenOddFillRule:YES];

CAShapeLayer *fillLayer = [CAShapeLayer layer];
fillLayer.path = dimmedPath.CGPath;
fillLayer.fillRule = kCAFillRuleEvenOdd;
fillLayer.fillColor = self.dimmingColor.CGColor;
fillLayer.opacity = self.opacity;
[self.layer addSublayer:fillLayer];
}

@end
19 changes: 19 additions & 0 deletions ShapeKit/ProgressView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// ProgressView.h
// GeoTourist
//
// Created by Denys Telezhkin on 17.07.14.
// Copyright (c) 2014 MLSDev. All rights reserved.
//

#import "ShapedView.h"

@interface ProgressView : ShapedView

-(void)setFrame:(CGRect)frame;

@property (nonatomic, assign) float progress;

@property (nonatomic, strong) UIColor * fillColor;

@end
59 changes: 59 additions & 0 deletions ShapeKit/ProgressView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// ProgressView.m
// GeoTourist
//
// Created by Denys Telezhkin on 17.07.14.
// Copyright (c) 2014 MLSDev. All rights reserved.
//

#import "ProgressView.h"

@implementation ProgressView

-(void)setFrame:(CGRect)frame
{
UIBezierPath * path = [UIBezierPath bezierPath];
path.lineWidth = frame.size.height;
[path moveToPoint:CGPointMake(0, frame.size.height/2)];
[path addLineToPoint:CGPointMake(frame.size.width, frame.size.height/2)];
self.path = path;
[super setFrame:frame];
}

static NSString * const kStrokeEndAnimationKey = @"Stroke end animation";

-(void)setProgress:(float)progress
{
NSParameterAssert(progress>=0);

if (progress>1)
{
progress =1;
}

[self.shapeLayer removeAnimationForKey:kStrokeEndAnimationKey];

[CATransaction begin];

CABasicAnimation * drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.fromValue = @(self.shapeLayer.strokeEnd);
drawAnimation.toValue = @(progress);
drawAnimation.duration = 0.05;
drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
drawAnimation.removedOnCompletion = YES;

self.shapeLayer.strokeEnd = progress;
_progress = progress;

[self.shapeLayer addAnimation:drawAnimation forKey:kStrokeEndAnimationKey];
[CATransaction commit];
}

-(void)setFillColor:(UIColor *)fillColor
{
self.shapeLayer.strokeColor = [fillColor CGColor];
self.shapeLayer.masksToBounds = YES;
_fillColor = fillColor;
}

@end
16 changes: 16 additions & 0 deletions ShapeKit/ShapedView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ShapedView.h
// GeoTourist
//
// Created by Denys Telezhkin on 17.07.14.
// Copyright (c) 2014 MLSDev. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ShapedView : UIView

@property (nonatomic, strong) UIBezierPath * path;
@property (nonatomic, strong, readonly) CAShapeLayer * shapeLayer;

@end
30 changes: 30 additions & 0 deletions ShapeKit/ShapedView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// ShapedView.m
// GeoTourist
//
// Created by Denys Telezhkin on 17.07.14.
// Copyright (c) 2014 MLSDev. All rights reserved.
//

#import "ShapedView.h"

@implementation ShapedView

+(Class)layerClass
{
return [CAShapeLayer class];
}

-(CAShapeLayer *)shapeLayer
{
return (CAShapeLayer*)self.layer;
}

-(void)setPath:(UIBezierPath *)path
{
_path = path;
self.shapeLayer.path = [_path CGPath];
self.shapeLayer.lineWidth = path.lineWidth;
}

@end
Loading

0 comments on commit c80f714

Please sign in to comment.