diff --git a/.cocoadocs.yml b/.cocoadocs.yml new file mode 100644 index 00000000..06686231 --- /dev/null +++ b/.cocoadocs.yml @@ -0,0 +1,10 @@ +body: '"Futura", "Helvetica Neue", "Arial", san-serif' +code: '"Monaco", "Menlo", "Consolas", "Courier New", monospace' + +highlight_color: "#e06431;" +highlight-dark-color: "#bb4312;" +darker-color: "#de906f;" +darker-dark-color: "#917f78;" +background-color: "#ede8e6;" +alt-link-color: "#bb4312;" +warning-color: "#ff4a00;" diff --git a/AMPopTip.podspec b/AMPopTip.podspec index 5f0d7c25..741b212f 100644 --- a/AMPopTip.podspec +++ b/AMPopTip.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "AMPopTip" - s.version = "0.1" + s.version = "0.2" s.summary = "Animated popover, great for subtle UI tips and onboarding." s.description = <<-DESC @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.homepage = "https://github.com/andreamazz/AMPopTip" s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "Andrea Mazzini" => "andrea.mazzini@gmail.com" } - s.source = { :git => "https://github.com/andreamazz/AMPopTip.git", :tag => '0.1' } + s.source = { :git => "https://github.com/andreamazz/AMPopTip.git", :tag => '0.2' } s.platform = :ios, '7.0' s.source_files = 'AMPopTip', '*.{h,m}' s.requires_arc = true diff --git a/AMPopTip/AMPopTip.h b/AMPopTip/AMPopTip.h index 39a10e86..75202266 100644 --- a/AMPopTip/AMPopTip.h +++ b/AMPopTip/AMPopTip.h @@ -1,6 +1,6 @@ // // AMPopTip.h -// PopTipDemo +// AMPopTip // // Created by Andrea Mazzini on 11/07/14. // Copyright (c) 2014 Fancy Pixel. All rights reserved. @@ -15,19 +15,92 @@ typedef NS_ENUM(NSInteger, AMPopTipDirection) { @interface AMPopTip : UIView +/**----------------------------------------------------------------------------- + * @name AMPopTip + * ----------------------------------------------------------------------------- + */ + ++ (instancetype)popTip; + +/** Show the popover + * + * Shows an animated popover in a given view, from a given rectangle. + * The property isVisible will be set as YES as soon as the popover is added to the given view. + * + * @param text The text displayed. + * @param direction The direction of the popover. + * @param maxWidth The maximum width of the popover. If the popover won't fit in the given space, this will be overridden. + * @param view The view that will hold the popover. + * @param frame The originating frame. The popover's arrow will point to the center of this frame. + */ +- (void)showText:(NSString *)text direction:(AMPopTipDirection)direction maxWidth:(CGFloat)maxWidth inView:(UIView *)view fromFrame:(CGRect)frame; + +/** Hide the popover + * + * Hides the popover and removes it from the view. + * The property isVisible will be set to NO when the animation is complete and the popover is removed from the parent view. + */ +- (void)hide; + + +/**----------------------------------------------------------------------------- +* @name AMPopTip Properties +* ----------------------------------------------------------------------------- +*/ + +/** Font + * + * Holds the UIFont used in the popover + */ @property (nonatomic, strong) UIFont *font UI_APPEARANCE_SELECTOR; + +/** Text Color + * + * Holds the UIColor of the text + */ @property (nonatomic, strong) UIColor *textColor UI_APPEARANCE_SELECTOR; + +/** Popover Background Color + * + * Holds the UIColor for the popover's background + */ @property (nonatomic, strong) UIColor *popoverColor UI_APPEARANCE_SELECTOR; + +/** Popover border radius + * + * Holds the CGFloat with the popover's border radius + */ @property (nonatomic, assign) CGFloat radius UI_APPEARANCE_SELECTOR; + +/** Text Padding + * + * Holds the CGFloat with the padding used for the inner text + */ @property (nonatomic, assign) CGFloat padding UI_APPEARANCE_SELECTOR; + +/** Arrow size + * + * Holds the CGSize with the width and height of the arrow + */ @property (nonatomic, assign) CGSize arrowSize UI_APPEARANCE_SELECTOR; + +/** Revealing Animation time + * + * Holds the NSTimeInterval with the duration of the revealing animation + */ @property (nonatomic, assign) NSTimeInterval animationIn UI_APPEARANCE_SELECTOR; -@property (nonatomic, assign) NSTimeInterval animationOut UI_APPEARANCE_SELECTOR; -@property (nonatomic, assign, readonly) BOOL isVisible; -+ (instancetype)popTip; +/** Disappearing Animation time + * + * Holds the NSTimeInterval with the duration of the disappearing animation + */ +@property (nonatomic, assign) NSTimeInterval animationOut UI_APPEARANCE_SELECTOR; -- (BOOL)showText:(NSString *)text direction:(AMPopTipDirection)direction maxWidth:(CGFloat)maxWidth inView:(UIView *)view fromFrame:(CGRect)frame; -- (BOOL)hide; +/** Visibility + * + * Holds the readonly BOOL with the popover visiblity. The popover is considered visible as soon as + * it's added as a subview, and invisible when the subview is removed from its parent. + */ +@property (nonatomic, assign, readonly) BOOL isVisible; @end diff --git a/AMPopTip/AMPopTip.m b/AMPopTip/AMPopTip.m index 30df250b..51454741 100644 --- a/AMPopTip/AMPopTip.m +++ b/AMPopTip/AMPopTip.m @@ -29,7 +29,6 @@ @interface AMPopTip() @property (nonatomic, strong) NSMutableParagraphStyle *paragraphStyle; @property (nonatomic, assign) CGFloat maxWidth; @property (nonatomic, assign) CGRect fromFrame; -@property (nonatomic, assign) BOOL isAnimating; @end @@ -60,7 +59,6 @@ - (instancetype)init _animationIn = kDefaultAnimationIn; _animationOut = kDefaultAnimationOut; _isVisible = NO; - _isAnimating = NO; } return self; } @@ -269,12 +267,8 @@ - (void)drawRect:(CGRect)rect [self.text drawInRect:self.textBounds withAttributes:titleAttributes]; } -- (BOOL)showText:(NSString *)text direction:(AMPopTipDirection)direction maxWidth:(CGFloat)maxWidth inView:(UIView *)view fromFrame:(CGRect)frame +- (void)showText:(NSString *)text direction:(AMPopTipDirection)direction maxWidth:(CGFloat)maxWidth inView:(UIView *)view fromFrame:(CGRect)frame { - if (_isVisible || _isAnimating) { - return NO; - } - self.text = text; self.direction = direction; self.containerView = view; @@ -283,35 +277,26 @@ - (BOOL)showText:(NSString *)text direction:(AMPopTipDirection)direction maxWidt [self setNeedsLayout]; - self.isAnimating = YES; self.transform = CGAffineTransformMakeScale(0, 0); [self.containerView addSubview:self]; + _isVisible = YES; - [UIView animateWithDuration:self.animationIn delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:3 options:UIViewAnimationOptionCurveEaseInOut animations:^{ + [UIView animateWithDuration:self.animationIn delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:3 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{ self.transform = CGAffineTransformIdentity; - } completion:^(BOOL finished) { - self.isAnimating = NO; - self->_isVisible = YES; - }]; - - return YES; + } completion:nil]; } -- (BOOL)hide +- (void)hide { - if (!_isVisible || _isAnimating) { - return NO; - } - self.isAnimating = YES; - [UIView animateWithDuration:self.animationOut delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ + [UIView animateWithDuration:self.animationOut delay:0 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState) animations:^{ self.transform = CGAffineTransformMakeScale(0.000001, 0.000001); } completion:^(BOOL finished) { - [self removeFromSuperview]; - self.transform = CGAffineTransformIdentity; - self.isAnimating = NO; - self->_isVisible = NO; + if (finished) { + [self removeFromSuperview]; + self.transform = CGAffineTransformIdentity; + self->_isVisible = NO; + } }]; - return YES; } @end