Skip to content

Commit

Permalink
Added self-dismiss after a time period
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamazz committed Sep 4, 2014
1 parent 460bedd commit e4a0ac7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions AMPopTip/AMPopTip.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ typedef NS_ENUM(NSInteger, AMPopTipDirection) {
*/
- (void)showText:(NSString *)text direction:(AMPopTipDirection)direction maxWidth:(CGFloat)maxWidth inView:(UIView *)view fromFrame:(CGRect)frame;

/** 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.
* @param interval The time interval that determines when the poptip will self-dismiss
*/
- (void)showText:(NSString *)text direction:(AMPopTipDirection)direction maxWidth:(CGFloat)maxWidth inView:(UIView *)view fromFrame:(CGRect)frame duration:(NSTimeInterval)interval;

/** Hide the popover
*
* Hides the popover and removes it from the view.
Expand Down
8 changes: 8 additions & 0 deletions AMPopTip/AMPopTip.m
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ - (void)showText:(NSString *)text direction:(AMPopTipDirection)direction maxWidt
} completion:nil];
}

- (void)showText:(NSString *)text direction:(AMPopTipDirection)direction maxWidth:(CGFloat)maxWidth inView:(UIView *)view fromFrame:(CGRect)frame duration:(NSTimeInterval)interval
{
[self showText:text direction:direction maxWidth:maxWidth inView:view fromFrame:frame];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(interval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self hide];
});
}

- (void)hide
{
if (self.superview) {
Expand Down
2 changes: 1 addition & 1 deletion PopTipDemo/PopTipDemo/AMViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (IBAction)actionButton:(UIButton *)sender
if (sender == self.buttonCenter) {
self.popTip.popoverColor = [UIColor colorWithRed:0.31 green:0.57 blue:0.87 alpha:1];
static int direction = 0;
[self.popTip showText:@"Animated popover, great for subtle UI tips and onboarding" direction:direction maxWidth:200 inView:self.view fromFrame:sender.frame];
[self.popTip showText:@"Animated popover, great for subtle UI tips and onboarding" direction:direction maxWidth:200 inView:self.view fromFrame:sender.frame duration:2];
direction = (direction + 1) % 4;
}
}
Expand Down

0 comments on commit e4a0ac7

Please sign in to comment.