Skip to content

Commit

Permalink
Popover with no arrow option
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvise Susmel committed Dec 24, 2012
1 parent 4bcf9bb commit 7a6e7af
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 18 deletions.
14 changes: 11 additions & 3 deletions FPPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ -(id)initWithViewController:(UIViewController*)viewController
_touchView.clipsToBounds = NO;
[self.view addSubview:_touchView];

__weak typeof (self) bself = self;
__block typeof (self) bself = self;
[_touchView setTouchedOutsideBlock:^{
[bself dismissPopoverAnimated:YES];
}];
Expand Down Expand Up @@ -217,7 +217,8 @@ -(void)presentPopoverFromPoint:(CGPoint)fromPoint
-(CGPoint)originFromView:(UIView*)fromView
{
CGPoint p;
if([_contentView arrowDirection] == FPPopoverArrowDirectionUp)
if([_contentView arrowDirection] == FPPopoverArrowDirectionUp ||
[_contentView arrowDirection] == FPPopoverNoArrow)
{
p.x = fromView.frame.origin.x + fromView.frame.size.width/2.0;
p.y = fromView.frame.origin.y + fromView.frame.size.height;
Expand Down Expand Up @@ -529,7 +530,14 @@ -(CGRect)bestArrowDirectionAndFrameFromView:(UIView*)v
if(r.origin.y <= 20) r.origin.y += 20;
}

_contentView.arrowDirection = bestDirection;
//check if the developer wants and arror
if(self.arrowDirection != FPPopoverNoArrow)
_contentView.arrowDirection = bestDirection;

//no arrow
else _contentView.arrowDirection = FPPopoverNoArrow;

//using the frame calculated
_contentView.frame = r;

self.origin = CGPointMake(p.x + v.frame.size.width/2.0, p.y + v.frame.size.height/2.0);
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion FPPopoverDemo/FPDemoTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ -(void)popover:(id)sender
popover.arrowDirection = FPPopoverArrowDirectionRight;

//sender is the UIButton view
[popover presentPopoverFromView:sender];
[popover presentPopoverFromView:sender];

}


Expand Down
1 change: 0 additions & 1 deletion FPPopoverDemo/FPViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ -(void)popover:(id)sender
controller.delegate = self;
popover = [[FPPopoverController alloc] initWithViewController:controller];

//popover.arrowDirection = FPPopoverArrowDirectionAny;
popover.tint = FPPopoverDefaultTint;

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
Expand Down
13 changes: 8 additions & 5 deletions FPPopoverView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ typedef enum FPPopoverArrowDirection: NSUInteger {
FPPopoverArrowDirectionDown = 1UL << 1,
FPPopoverArrowDirectionLeft = 1UL << 2,
FPPopoverArrowDirectionRight = 1UL << 3,

FPPopoverArrowDirectionVertical = FPPopoverArrowDirectionUp | FPPopoverArrowDirectionDown,
FPPopoverNoArrow = 1UL << 4,

FPPopoverArrowDirectionVertical = FPPopoverArrowDirectionUp | FPPopoverArrowDirectionDown | FPPopoverNoArrow,
FPPopoverArrowDirectionHorizontal = FPPopoverArrowDirectionLeft | FPPopoverArrowDirectionRight,

FPPopoverArrowDirectionAny = FPPopoverArrowDirectionUp | FPPopoverArrowDirectionDown |
FPPopoverArrowDirectionLeft | FPPopoverArrowDirectionRight

} FPPopoverArrowDirection;

#ifndef FPPopoverArrowDirectionIsVertical
#define FPPopoverArrowDirectionIsVertical(direction) ((direction) == FPPopoverArrowDirectionVertical || (direction) == FPPopoverArrowDirectionUp || (direction) == FPPopoverArrowDirectionDown || (direction) == FPPopoverNoArrow)
#endif

#define FPPopoverArrowDirectionIsVertical(direction) ((direction) == FPPopoverArrowDirectionVertical || (direction) == FPPopoverArrowDirectionUp || (direction) == FPPopoverArrowDirectionDown)

#ifndef FPPopoverArrowDirectionIsHorizontal
#define FPPopoverArrowDirectionIsHorizontal(direction) ((direction) == FPPopoverArrowDirectionHorizontal || (direction) == FPPopoverArrowDirectionLeft || (direction) == FPPopoverArrowDirectionRight)

#endif

typedef enum {
FPPopoverBlackTint,
Expand Down
29 changes: 25 additions & 4 deletions FPPopoverView.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,25 @@ -(CGPathRef)newContentPathWithBorderWidth:(CGFloat)borderWidth arrowDirection:(F
rect.origin.x = b;
rect.origin.y = b;
}
else
else if(direction == FPPopoverArrowDirectionLeft)
{
//Assuming direction == FPPopoverArrowDirectionLeft to suppress static analyzer warnings
rect.size.width = w - ah - 2*b;
rect.size.height = h - 2*b;
rect.origin.x = ah + b;
rect.origin.y = b;
rect.origin.y = b;
}

//NO ARROW
else
{
rect.size.width = w - 2*b;
rect.size.height = h - 2*b;
rect.origin.x = b;
rect.origin.y = b;
}



//the arrow will be near the origin
CGFloat ax = self.relativeOrigin.x - aw; //the start of the arrow when UP or DOWN
if(ax < aw + b) ax = aw + b;
Expand Down Expand Up @@ -309,7 +319,7 @@ - (void)drawRect:(CGRect)rect
// Draw a linear gradient from top to bottom
CGPoint start;
CGPoint end;
if(_arrowDirection == FPPopoverArrowDirectionUp)
if(_arrowDirection == FPPopoverArrowDirectionUp || _arrowDirection == FPPopoverNoArrow)
{
start = CGPointMake(self.bounds.size.width/2.0, 0);
end = CGPointMake(self.bounds.size.width/2.0,40);
Expand Down Expand Up @@ -429,6 +439,17 @@ -(void)setupViews
contentRect.size = CGSizeMake(self.bounds.size.width-40, self.bounds.size.height-20);
}
}

else if(_arrowDirection == FPPopoverNoArrow)
{
contentRect.origin = CGPointMake(10, 40);
contentRect.size = CGSizeMake(self.bounds.size.width-20, self.bounds.size.height-50);
_titleLabel.frame = CGRectMake(10, 10, self.bounds.size.width-20, 20);
if (self.title==nil || self.title.length==0) {
contentRect.origin = CGPointMake(10, 30);
contentRect.size = CGSizeMake(self.bounds.size.width-20, self.bounds.size.height-40);
}
}

_contentView.frame = contentRect;
_titleLabel.text = self.title;
Expand Down
4 changes: 2 additions & 2 deletions FPTouchView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ typedef void (^FPTouchedInsideBlock)();

@interface FPTouchView : UIView
{
FPTouchedOutsideBlock _outsideBlock;
FPTouchedInsideBlock _insideBlock;
__strong FPTouchedOutsideBlock _outsideBlock;
__strong FPTouchedInsideBlock _insideBlock;
}

-(void)setTouchedOutsideBlock:(FPTouchedOutsideBlock)outsideBlock;
Expand Down
4 changes: 2 additions & 2 deletions FPTouchView.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ @implementation FPTouchView

-(void)setTouchedOutsideBlock:(FPTouchedOutsideBlock)outsideBlock
{
_outsideBlock = [outsideBlock copy];
_outsideBlock = outsideBlock;
}

-(void)setTouchedInsideBlock:(FPTouchedInsideBlock)insideBlock
{
_insideBlock = [insideBlock copy];
_insideBlock = insideBlock;
}

-(UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
Expand Down

0 comments on commit 7a6e7af

Please sign in to comment.