Skip to content

Commit 19f7401

Browse files
Merge pull request #43 from scastria/master
Use popover controller like a custom dialog popup by scastria
2 parents e9a53c3 + 46e4960 commit 19f7401

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

WYPopoverController/WYPopoverController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef NS_OPTIONS(NSUInteger, WYPopoverArrowDirection) {
3838
WYPopoverArrowDirectionDown = 1UL << 1,
3939
WYPopoverArrowDirectionLeft = 1UL << 2,
4040
WYPopoverArrowDirectionRight = 1UL << 3,
41+
WYPopoverArrowDirectionNone = 1UL << 4,
4142
WYPopoverArrowDirectionAny = WYPopoverArrowDirectionUp | WYPopoverArrowDirectionDown | WYPopoverArrowDirectionLeft | WYPopoverArrowDirectionRight,
4243
WYPopoverArrowDirectionUnknown = NSUIntegerMax
4344
};
@@ -103,6 +104,8 @@ typedef NS_OPTIONS(NSUInteger, WYPopoverArrowDirection) {
103104
permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections
104105
animated:(BOOL)animated;
105106

107+
- (void)presentPopoverAsDialogAnimated:(BOOL)animated;
108+
106109
- (void)dismissPopoverAnimated:(BOOL)animated;
107110

108111
@end

WYPopoverController/WYPopoverController.m

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ - (NSString*)description
144144
{
145145
direction = @"RIGHT";
146146
}
147+
else if (arrowDirection == WYPopoverArrowDirectionNone)
148+
{
149+
direction = @"NONE";
150+
}
147151

148152
return [NSString stringWithFormat:@"%@ [ %f x %f ]", direction, areaSize.width, areaSize.height];
149153
}
@@ -995,7 +999,7 @@ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
995999
reducedOuterCornerRadius = (CGRectGetMidX(outerRect) + arrowOffset - arrowBase / 2) - CGRectGetMinX(outerRect);
9961000
}
9971001
}
998-
else
1002+
else if (arrowDirection == WYPopoverArrowDirectionLeft || arrowDirection == WYPopoverArrowDirectionRight)
9991003
{
10001004
if (arrowOffset >= 0)
10011005
{
@@ -1077,6 +1081,23 @@ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
10771081
CGPathAddLineToPoint(outerPathRef, NULL, origin.x, origin.y);
10781082
}
10791083

1084+
if (arrowDirection == WYPopoverArrowDirectionNone)
1085+
{
1086+
origin = CGPointMake(CGRectGetMaxX(outerRect), CGRectGetMidY(outerRect));
1087+
1088+
CGPathMoveToPoint(outerPathRef, NULL, origin.x, origin.y);
1089+
1090+
CGPathAddLineToPoint(outerPathRef, NULL, CGRectGetMaxX(outerRect), CGRectGetMidY(outerRect));
1091+
CGPathAddLineToPoint(outerPathRef, NULL, CGRectGetMaxX(outerRect), CGRectGetMidY(outerRect));
1092+
1093+
CGPathAddArcToPoint(outerPathRef, NULL, CGRectGetMaxX(outerRect), CGRectGetMaxY(outerRect), CGRectGetMinX(outerRect), CGRectGetMaxY(outerRect), outerCornerRadius);
1094+
CGPathAddArcToPoint(outerPathRef, NULL, CGRectGetMinX(outerRect), CGRectGetMaxY(outerRect), CGRectGetMinX(outerRect), CGRectGetMinY(outerRect), outerCornerRadius);
1095+
CGPathAddArcToPoint(outerPathRef, NULL, CGRectGetMinX(outerRect), CGRectGetMinY(outerRect), CGRectGetMaxX(outerRect), CGRectGetMinY(outerRect), outerCornerRadius);
1096+
CGPathAddArcToPoint(outerPathRef, NULL, CGRectGetMaxX(outerRect), CGRectGetMinY(outerRect), CGRectGetMaxX(outerRect), CGRectGetMaxY(outerRect), outerCornerRadius);
1097+
1098+
CGPathAddLineToPoint(outerPathRef, NULL, origin.x, origin.y);
1099+
}
1100+
10801101
CGPathCloseSubpath(outerPathRef);
10811102

10821103
UIBezierPath* outerRectPath = [UIBezierPath bezierPathWithCGPath:outerPathRef];
@@ -1589,6 +1610,11 @@ - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDi
15891610
[self presentPopoverFromRect:itemView.bounds inView:itemView permittedArrowDirections:arrowDirections animated:aAnimated];
15901611
}
15911612

1613+
- (void)presentPopoverAsDialogAnimated:(BOOL)aAnimated
1614+
{
1615+
[self presentPopoverFromRect:CGRectZero inView:nil permittedArrowDirections:WYPopoverArrowDirectionNone animated:aAnimated];
1616+
}
1617+
15921618
- (void)positionPopover
15931619
{
15941620
CGSize contentViewSize = self.contentSizeForViewInPopover;
@@ -1821,6 +1847,24 @@ - (void)positionPopover
18211847
containerView.arrowOffset = offset;
18221848
}
18231849

1850+
if (arrowDirection == WYPopoverArrowDirectionNone)
1851+
{
1852+
containerView.arrowDirection = WYPopoverArrowDirectionNone;
1853+
containerViewSize = [containerView sizeThatFits:contentViewSize];
1854+
1855+
containerFrame = CGRectZero;
1856+
containerFrame.size = containerViewSize;
1857+
containerFrame.size.width = MIN(maxX - minX, containerFrame.size.width);
1858+
containerFrame.size.height = MIN(maxY - minY, containerFrame.size.height);
1859+
containerView.frame = containerFrame;
1860+
1861+
containerView.center = CGPointMake(minX + (maxX - minX) / 2, minY + (maxY - minY) / 2);
1862+
1863+
containerFrame = containerView.frame;
1864+
1865+
containerView.arrowOffset = offset;
1866+
}
1867+
18241868
containerView.frame = containerFrame;
18251869

18261870
containerView.wantsDefaultContentAppearance = wantsDefaultContentAppearance;
@@ -1965,6 +2009,14 @@ - (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
19652009
area.arrowDirection = WYPopoverArrowDirectionRight;
19662010
[areas addObject:area];
19672011
}
2012+
2013+
if ((arrowDirections & WYPopoverArrowDirectionNone) == WYPopoverArrowDirectionNone)
2014+
{
2015+
area = [[WYPopoverArea alloc] init];
2016+
area.areaSize = [self sizeForRect:aRect inView:aView arrowHeight:arrowHeight arrowDirection:WYPopoverArrowDirectionNone];
2017+
area.arrowDirection = WYPopoverArrowDirectionNone;
2018+
[areas addObject:area];
2019+
}
19682020

19692021
if ([areas count] > 1)
19702022
{
@@ -2080,6 +2132,11 @@ - (CGSize)sizeForRect:(CGRect)aRect
20802132
result.height = maxY - (viewFrame.origin.y + viewFrame.size.height);
20812133
result.height -= arrowHeight;
20822134
}
2135+
else if (arrowDirection == WYPopoverArrowDirectionNone)
2136+
{
2137+
result.width = maxX - minX;
2138+
result.height = maxY - minY;
2139+
}
20832140

20842141
return result;
20852142
}

0 commit comments

Comments
 (0)