136 lines
4.7 KiB
Objective-C
136 lines
4.7 KiB
Objective-C
/*
|
|
Copyright (c) 2019, Apple Inc. All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
this list of conditions and the following disclaimer in the documentation and/or
|
|
other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
|
may be used to endorse or promote products derived from this software without
|
|
specific prior written permission. No license is granted to the trademarks of
|
|
the copyright holders even if such marks are included in this software.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#import "ORKCompletionCheckmarkView.h"
|
|
#import "ORKSkin.h"
|
|
#import "ORKHelpers_Internal.h"
|
|
|
|
|
|
@implementation ORKCompletionCheckmarkView {
|
|
CAShapeLayer *_shapeLayer;
|
|
CGFloat tickViewSize;
|
|
|
|
}
|
|
|
|
+ (instancetype)new {
|
|
ORKThrowMethodUnavailableException();
|
|
}
|
|
|
|
- (instancetype)init {
|
|
ORKThrowMethodUnavailableException();
|
|
}
|
|
|
|
- (instancetype)initWithDimension:(CGFloat)dimension {
|
|
self = [super init];
|
|
if (self) {
|
|
tickViewSize = dimension;
|
|
self.layer.cornerRadius = tickViewSize / 2;
|
|
[self tintColorDidChange];
|
|
|
|
UIBezierPath *path = [UIBezierPath new];
|
|
[path moveToPoint:(CGPoint){0.27*tickViewSize, 0.52*tickViewSize}];
|
|
[path addLineToPoint:(CGPoint){0.42*tickViewSize, 0.68*tickViewSize}];
|
|
[path addLineToPoint:(CGPoint){0.68*tickViewSize, 0.32*tickViewSize}];
|
|
path.lineCapStyle = kCGLineCapRound;
|
|
|
|
CAShapeLayer *shapeLayer = [CAShapeLayer new];
|
|
shapeLayer.path = path.CGPath;
|
|
shapeLayer.lineWidth = 0.10*tickViewSize;
|
|
shapeLayer.lineCap = kCALineCapRound;
|
|
shapeLayer.lineJoin = kCALineJoinRound;
|
|
shapeLayer.frame = self.layer.bounds;
|
|
shapeLayer.strokeColor = [UIColor whiteColor].CGColor;
|
|
shapeLayer.backgroundColor = [UIColor clearColor].CGColor;
|
|
shapeLayer.fillColor = nil;
|
|
[self.layer addSublayer:shapeLayer];
|
|
_shapeLayer = shapeLayer;
|
|
|
|
self.translatesAutoresizingMaskIntoConstraints = NO;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithDefaultDimension {
|
|
return [self initWithDimension:ORKStepContentIconImageViewDimension];
|
|
}
|
|
|
|
- (void)layoutSubviews {
|
|
[super layoutSubviews];
|
|
_shapeLayer.frame = self.layer.bounds;
|
|
}
|
|
|
|
- (CGSize)intrinsicContentSize {
|
|
return (CGSize){tickViewSize, tickViewSize};
|
|
}
|
|
|
|
- (CGSize)sizeThatFits:(CGSize)size {
|
|
return [self intrinsicContentSize];
|
|
}
|
|
|
|
- (void)tintColorDidChange {
|
|
self.backgroundColor = [self tintColor];
|
|
}
|
|
|
|
- (void)setAnimationPoint:(CGFloat)animationPoint {
|
|
_shapeLayer.strokeEnd = animationPoint;
|
|
_animationPoint = animationPoint;
|
|
}
|
|
|
|
- (void)setAnimationPoint:(CGFloat)animationPoint animated:(BOOL)animated {
|
|
CAMediaTimingFunction *timing = [[CAMediaTimingFunction alloc] initWithControlPoints:0.180739998817444 :0 :0.577960014343262 :0.918200016021729];
|
|
|
|
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
|
|
[animation setTimingFunction:timing];
|
|
[animation setFillMode:kCAFillModeBoth];
|
|
animation.fromValue = @([(CAShapeLayer *)[_shapeLayer presentationLayer] strokeEnd]);
|
|
animation.toValue = @(animationPoint);
|
|
|
|
animation.duration = 0.3;
|
|
_animationPoint = animationPoint;
|
|
|
|
_shapeLayer.strokeEnd = animationPoint;
|
|
[_shapeLayer addAnimation:animation forKey:@"strokeEnd"];
|
|
|
|
}
|
|
|
|
- (BOOL)isAccessibilityElement {
|
|
return YES;
|
|
}
|
|
|
|
- (UIAccessibilityTraits)accessibilityTraits {
|
|
return [super accessibilityTraits] | UIAccessibilityTraitImage;
|
|
}
|
|
|
|
- (NSString *)accessibilityLabel {
|
|
return ORKLocalizedString(@"AX_COMPLETION_ILLUSTRATION", nil);
|
|
}
|
|
|
|
@end
|