Skip to content

Commit

Permalink
Added a dismissTapAnywhere option
Browse files Browse the repository at this point in the history
When enabled the user can tap anywhere on the container view to dismiss
the popup.
  • Loading branch information
StephenWakely committed Jun 25, 2012
1 parent 3b207f2 commit e5770c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMPopTipView/CMPopTipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ typedef enum {
PointDirection pointDirection;
CGFloat pointerSize;
CGPoint targetPoint;
UIButton *dismissTarget;
}

@property (nonatomic, retain) UIColor *backgroundColor;
@property (nonatomic, assign) id<CMPopTipViewDelegate> delegate;
@property (nonatomic, assign) BOOL disableTapToDismiss;
@property (nonatomic, assign) BOOL dismissTapAnywhere;
@property (nonatomic, retain) NSString *message;
@property (nonatomic, retain) UIView *customView;
@property (nonatomic, retain, readonly) id targetObject;
Expand Down
17 changes: 17 additions & 0 deletions CMPopTipView/CMPopTipView.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ @implementation CMPopTipView
@synthesize animation;
@synthesize maxWidth;
@synthesize disableTapToDismiss;
@synthesize dismissTapAnywhere;

- (CGRect)bubbleFrame {
CGRect bubbleFrame;
Expand Down Expand Up @@ -235,6 +236,16 @@ - (void)presentPointingAtView:(UIView *)targetView inView:(UIView *)containerVie
if (!self.targetObject) {
self.targetObject = targetView;
}

// If we want to dismiss the bubble when the user taps anywhere, we need to insert
// an invisible button over the background.
if ( self.dismissTapAnywhere ) {
self->dismissTarget = [UIButton buttonWithType:UIButtonTypeCustom];
[self->dismissTarget addTarget:self action:@selector(touchesBegan:withEvent:) forControlEvents:UIControlEventTouchUpInside];
[self->dismissTarget setTitle:@"" forState:UIControlStateNormal];
self->dismissTarget.frame = containerView.bounds;
[containerView addSubview:self->dismissTarget];
}

[containerView addSubview:self];

Expand Down Expand Up @@ -409,6 +420,11 @@ - (void)presentPointingAtBarButtonItem:(UIBarButtonItem *)barButtonItem animated

- (void)finaliseDismiss {
[self removeFromSuperview];

if ( self->dismissTarget ) {
[self->dismissTarget removeFromSuperview];
}

highlight = NO;
self.targetObject = nil;
}
Expand Down Expand Up @@ -491,6 +507,7 @@ - (id)initWithFrame:(CGRect)frame {
self.backgroundColor = [UIColor colorWithRed:62.0/255.0 green:60.0/255.0 blue:154.0/255.0 alpha:1.0];
self.borderColor = [UIColor blackColor];
self.animation = CMPopTipAnimationSlide;
self.dismissTapAnywhere = NO;
}
return self;
}
Expand Down

0 comments on commit e5770c6

Please sign in to comment.