diff --git a/src/Components/MRIconView.h b/src/Components/MRIconView.h index 7862273..678ea26 100644 --- a/src/Components/MRIconView.h +++ b/src/Components/MRIconView.h @@ -8,7 +8,6 @@ #import - /** Base class for icons which are given by an UIBezierPath and drawn with a CAShapeLayer. Their circular outer border and their line is colored in their tintColor. @@ -16,23 +15,30 @@ @interface MRIconView : UIView /** - Inner path. + Duration of an animated progress change. + + Default is 0.0 which means no animation is used. The recommended value is 0.5. */ -- (UIBezierPath *)path; +@property (nonatomic, assign) CFTimeInterval animationDuration UI_APPEARANCE_SELECTOR; /** - The line Width of circle + The line width of the outer circle Default is 1.0. Must be larger than zero. */ -@property (nonatomic) CGFloat borderWidth UI_APPEARANCE_SELECTOR; +@property (nonatomic, assign) CGFloat borderWidth UI_APPEARANCE_SELECTOR; /** - The line width of icon + The line width of the icon Default is 1.0. Must be larger than zero. */ -@property (nonatomic) CGFloat lineWidth UI_APPEARANCE_SELECTOR; +@property (nonatomic, assign) CGFloat lineWidth UI_APPEARANCE_SELECTOR; + +/** + Inner path. + */ +- (UIBezierPath *)path; @end @@ -41,7 +47,6 @@ Draws a checkmark. */ @interface MRCheckmarkIconView : MRIconView - @end @@ -49,5 +54,4 @@ Draws a cross. */ @interface MRCrossIconView : MRIconView - @end diff --git a/src/Components/MRIconView.m b/src/Components/MRIconView.m index 061d039..7126019 100644 --- a/src/Components/MRIconView.m +++ b/src/Components/MRIconView.m @@ -9,6 +9,9 @@ #import "MRIconView.h" #import +@interface MRIconView () +@property (nonatomic, assign) BOOL animating; +@end @implementation MRIconView @@ -49,6 +52,7 @@ - (void)commonInit { self.isAccessibilityElement = YES; self.shapeLayer.fillColor = UIColor.clearColor.CGColor; + self.animating = NO; [self tintColorDidChange]; } @@ -70,33 +74,64 @@ - (void)setFrame:(CGRect)frame { self.layer.cornerRadius = frame.size.width / 2.0f; } -#pragma mark - Properties +#pragma mark - Appearance -- (CGFloat)borderWidth { - return self.layer.borderWidth; +- (CGFloat)borderWidth{ + return self.layer.borderWidth; } - (void)setBorderWidth:(CGFloat)borderWidth { - self.layer.borderWidth = borderWidth; + self.layer.borderWidth = borderWidth; } - (CGFloat)lineWidth { - return self.shapeLayer.lineWidth; + return self.shapeLayer.lineWidth; } - (void)setLineWidth:(CGFloat)lineWidth { - self.shapeLayer.lineWidth = lineWidth; + self.shapeLayer.lineWidth = lineWidth; } +#pragma mark - Animation -@end +- (void)startAnimating { + if (self.animating || self.animationDuration == 0.0) return; + self.animating = YES; + [self addAnimation]; +} + +- (void)stopAnimating { + if (!self.animating) return; + self.animating = NO; + [self removeAnimation]; +} + +- (BOOL)isAnimating { + return self.animating; +} +- (void)addAnimation { + CABasicAnimation *drawShapeAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; + drawShapeAnimation.duration = self.animationDuration; + drawShapeAnimation.removedOnCompletion = NO; + drawShapeAnimation.fillMode = kCAFillModeBoth; + drawShapeAnimation.fromValue = @(0); + drawShapeAnimation.toValue = @(1); + drawShapeAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; + [self.shapeLayer addAnimation:drawShapeAnimation forKey:@"DrawShape"]; +} + +- (void)removeAnimation { + [self.shapeLayer removeAnimationForKey:@"DrawShape"]; +} + +@end @implementation MRCheckmarkIconView - (void)commonInit { [super commonInit]; - + self.accessibilityLabel = NSLocalizedString(@"Checkmark", @"Accessibility label for custom rendered checkmark icon"); } @@ -113,7 +148,6 @@ - (UIBezierPath *)path { @end - @implementation MRCrossIconView - (void)commonInit { diff --git a/src/Components/MRProgressOverlayView.h b/src/Components/MRProgressOverlayView.h index 578dc3d..d7f13c1 100644 --- a/src/Components/MRProgressOverlayView.h +++ b/src/Components/MRProgressOverlayView.h @@ -144,6 +144,20 @@ typedef NS_ENUM(NSUInteger, MRProgressOverlayViewMode){ */ @property (nonatomic, assign) MRProgressOverlayViewMode mode; +/** + Minimum width to use when laying out the overlay view. + + Default value is 150.0. + */ +@property (nonatomic, assign) CGFloat overlayViewMinWidth; + +/** + Maximum height to use when laying out the title label. + + Default value is MAXFLOAT, which means not set. + */ +@property (nonatomic, assign) CGFloat titleLabelMaxHeight; + /** Current progress. diff --git a/src/Components/MRProgressOverlayView.m b/src/Components/MRProgressOverlayView.m index 1d1601e..87bb497 100644 --- a/src/Components/MRProgressOverlayView.m +++ b/src/Components/MRProgressOverlayView.m @@ -174,6 +174,8 @@ - (void)commonInit { self.hidden = YES; self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.overlayViewMinWidth = 150; + self.titleLabelMaxHeight = MAXFLOAT; const CGFloat cornerRadius = MRProgressOverlayViewCornerRadius; @@ -668,7 +670,7 @@ - (void)manualLayoutSubviews { const CGFloat dialogPadding = 15; const CGFloat modePadding = 30; const CGFloat dialogMargin = 10; - const CGFloat dialogMinWidth = 150; + CGFloat dialogMinWidth = self.overlayViewMinWidth; const BOOL hasSmallIndicator = self.mode == MRProgressOverlayViewModeIndeterminateSmall || self.mode == MRProgressOverlayViewModeIndeterminateSmallDefault; @@ -702,9 +704,9 @@ - (void)manualLayoutSubviews { y += 3; - CGSize titleLabelMaxSize = CGSizeMake(titleLabelMaxWidth, self.bounds.size.height); + CGSize titleLabelMaxSize = CGSizeMake(titleLabelMaxWidth, self.titleLabelMaxHeight != MAXFLOAT ? self.titleLabelMaxHeight : self.bounds.size.height); CGRect boundingRect = [self.titleLabel.attributedText boundingRectWithSize:titleLabelMaxSize - options:NSStringDrawingUsesLineFragmentOrigin + options:NSStringDrawingUsesLineFragmentOrigin | (self.titleLabelMaxHeight != MAXFLOAT ? NSStringDrawingTruncatesLastVisibleLine : 0) context:nil]; CGSize titleLabelSize = CGSizeMake(MRCGFloatCeil(boundingRect.size.width), MRCGFloatCeil(boundingRect.size.height)); diff --git a/src/Utils/MRProgressHelper.h b/src/Utils/MRProgressHelper.h index 0213170..9357dad 100644 --- a/src/Utils/MRProgressHelper.h +++ b/src/Utils/MRProgressHelper.h @@ -38,6 +38,7 @@ static inline CGRect MRCenterCGSizeInCGRect(CGSize innerRectSize, CGRect outerRe static inline CGFloat MRRotationForStatusBarOrientation() { +#ifndef APP_EXTENSION UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation; if (orientation == UIInterfaceOrientationLandscapeLeft) { return -M_PI_2; @@ -46,5 +47,7 @@ static inline CGFloat MRRotationForStatusBarOrientation() { } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) { return M_PI; } +#endif return 0; } +