Skip to content

Commit

Permalink
Updated to 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamazz committed Jul 21, 2014
1 parent 2d5990a commit 795a5f4
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 34 deletions.
10 changes: 10 additions & 0 deletions .cocoadocs.yml
Original file line number Diff line number Diff line change
@@ -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;"
4 changes: 2 additions & 2 deletions AMPopTip.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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" => "[email protected]" }
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
Expand Down
85 changes: 79 additions & 6 deletions AMPopTip/AMPopTip.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// AMPopTip.h
// PopTipDemo
// AMPopTip
//
// Created by Andrea Mazzini on 11/07/14.
// Copyright (c) 2014 Fancy Pixel. All rights reserved.
Expand All @@ -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
37 changes: 11 additions & 26 deletions AMPopTip/AMPopTip.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -60,7 +59,6 @@ - (instancetype)init
_animationIn = kDefaultAnimationIn;
_animationOut = kDefaultAnimationOut;
_isVisible = NO;
_isAnimating = NO;
}
return self;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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

0 comments on commit 795a5f4

Please sign in to comment.