@@ -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 {
@@ -1009,22 +1013,6 @@ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
10091013
10101014 reducedOuterCornerRadius = MIN (reducedOuterCornerRadius, outerCornerRadius);
10111015
1012- if (arrowDirection == WYPopoverArrowDirectionNone)
1013- {
1014- origin = CGPointMake (CGRectGetMidX (outerRect), CGRectGetMinY (outerRect));
1015-
1016- CGPathMoveToPoint (outerPathRef, NULL , origin.x , origin.y );
1017-
1018- CGPathAddLineToPoint (outerPathRef, NULL , CGRectGetMaxX (outerRect) - outerCornerRadius, CGRectGetMinY (outerRect));
1019-
1020- CGPathAddArcToPoint (outerPathRef, NULL , CGRectGetMaxX (outerRect), CGRectGetMinY (outerRect), CGRectGetMaxX (outerRect), CGRectGetMaxY (outerRect), outerCornerRadius);
1021- CGPathAddArcToPoint (outerPathRef, NULL , CGRectGetMaxX (outerRect), CGRectGetMaxY (outerRect), CGRectGetMinX (outerRect), CGRectGetMaxY (outerRect), outerCornerRadius);
1022- CGPathAddArcToPoint (outerPathRef, NULL , CGRectGetMinX (outerRect), CGRectGetMaxY (outerRect), CGRectGetMinX (outerRect), CGRectGetMinY (outerRect), outerCornerRadius);
1023- CGPathAddArcToPoint (outerPathRef, NULL , CGRectGetMinX (outerRect), CGRectGetMinY (outerRect), CGRectGetMaxX (outerRect), CGRectGetMinY (outerRect), outerCornerRadius);
1024-
1025- CGPathAddLineToPoint (outerPathRef, NULL , origin.x , origin.y );
1026- }
1027-
10281016 if (arrowDirection == WYPopoverArrowDirectionUp)
10291017 {
10301018 origin = CGPointMake (CGRectGetMidX (outerRect) + arrowOffset - arrowBase / 2 , CGRectGetMinY (outerRect));
@@ -1093,6 +1081,23 @@ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
10931081 CGPathAddLineToPoint (outerPathRef, NULL , origin.x , origin.y );
10941082 }
10951083
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+
10961101 CGPathCloseSubpath (outerPathRef);
10971102
10981103 UIBezierPath* outerRectPath = [UIBezierPath bezierPathWithCGPath: outerPathRef];
@@ -1230,7 +1235,7 @@ - (CGRect)arrowRect:(CGRect)rect arrowDirection:(WYPopoverArrowDirection)aArrowD
12301235{
12311236 CGRect result = CGRectZero;
12321237
1233- if (arrowHeight > 0 && aArrowDirection != WYPopoverArrowDirectionDown )
1238+ if (arrowHeight > 0 )
12341239 {
12351240 result.size = CGSizeMake (arrowBase, arrowHeight);
12361241
@@ -1432,10 +1437,14 @@ - (CGSize)contentSizeForViewInPopover
14321437
14331438 UIViewController *controller = viewController;
14341439
1435- UINavigationController *navigationController = (UINavigationController *)controller;
1436- if ([[navigationController viewControllers ] count ] > 0 )
1440+ if ([controller isKindOfClass: [UINavigationController class ]])
14371441 {
1438- controller = (UIViewController *)[[navigationController viewControllers ] objectAtIndex: 0 ];
1442+ UINavigationController *navigationController = (UINavigationController *)controller;
1443+
1444+ if ([[navigationController viewControllers ] count ] > 0 )
1445+ {
1446+ controller = (UIViewController *)[[navigationController viewControllers ] objectAtIndex: 0 ];
1447+ }
14391448 }
14401449
14411450#ifdef WY_BASE_SDK_7_ENABLED
@@ -1444,12 +1453,10 @@ - (CGSize)contentSizeForViewInPopover
14441453 result = controller.preferredContentSize ;
14451454 }
14461455#endif
1447-
14481456 if (CGSizeEqualToSize (result, CGSizeZero))
14491457 {
14501458#pragma clang diagnostic push
14511459#pragma GCC diagnostic ignored "-Wdeprecated"
1452-
14531460 result = controller.contentSizeForViewInPopover ;
14541461#pragma clang diagnostic pop
14551462 }
@@ -1615,6 +1622,11 @@ - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDi
16151622 [self presentPopoverFromRect: itemView.bounds inView: itemView permittedArrowDirections: arrowDirections animated: aAnimated];
16161623}
16171624
1625+ - (void )presentPopoverAsDialogAnimated : (BOOL )aAnimated
1626+ {
1627+ [self presentPopoverFromRect: CGRectZero inView: nil permittedArrowDirections: WYPopoverArrowDirectionNone animated: aAnimated];
1628+ }
1629+
16181630- (void )positionPopover
16191631{
16201632 CGSize contentViewSize = self.contentSizeForViewInPopover ;
@@ -1630,7 +1642,7 @@ - (void)positionPopover
16301642
16311643 overlayView.frame = self.rootView .bounds ;
16321644
1633- viewFrame = (permittedArrowDirections != WYPopoverArrowDirectionNone) ? [overlayView convertRect: rect fromView: inView] : overlayView. bounds ;
1645+ viewFrame = [overlayView convertRect: rect fromView: inView];
16341646
16351647 minX = popoverLayoutMargins.left ;
16361648 maxX = self.rootView .bounds .size .width - popoverLayoutMargins.right ;
@@ -1858,11 +1870,11 @@ - (void)positionPopover
18581870 containerFrame.size .height = MIN (maxY - minY, containerFrame.size .height );
18591871 containerView.frame = containerFrame;
18601872
1861- containerView.center = CGPointMake (viewFrame. size . width / 2 , viewFrame. size . height / 2 );
1873+ containerView.center = CGPointMake (minX + (maxX - minX) / 2 , minY + (maxY - minY) / 2 );
18621874
18631875 containerFrame = containerView.frame ;
18641876
1865- containerView.arrowOffset = 0 ;
1877+ containerView.arrowOffset = offset ;
18661878 }
18671879
18681880 containerView.frame = containerFrame;
@@ -1975,13 +1987,8 @@ - (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
19751987{
19761988 WYPopoverArrowDirection arrowDirection = WYPopoverArrowDirectionUnknown;
19771989
1978- if (arrowDirections == WYPopoverArrowDirectionNone)
1979- {
1980- arrowDirection = WYPopoverArrowDirectionNone;
1981- }
1982-
1983- NSMutableArray *areas = [NSMutableArray arrayWithCapacity: 0 ];
1984- WYPopoverArea *area;
1990+ NSMutableArray * areas = [NSMutableArray arrayWithCapacity: 0 ];
1991+ WYPopoverArea* area;
19851992
19861993 if ((arrowDirections & WYPopoverArrowDirectionDown) == WYPopoverArrowDirectionDown)
19871994 {
@@ -2014,6 +2021,14 @@ - (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
20142021 area.arrowDirection = WYPopoverArrowDirectionRight;
20152022 [areas addObject: area];
20162023 }
2024+
2025+ if ((arrowDirections & WYPopoverArrowDirectionNone) == WYPopoverArrowDirectionNone)
2026+ {
2027+ area = [[WYPopoverArea alloc ] init ];
2028+ area.areaSize = [self sizeForRect: aRect inView: aView arrowHeight: arrowHeight arrowDirection: WYPopoverArrowDirectionNone];
2029+ area.arrowDirection = WYPopoverArrowDirectionNone;
2030+ [areas addObject: area];
2031+ }
20172032
20182033 if ([areas count ] > 1 )
20192034 {
@@ -2129,6 +2144,11 @@ - (CGSize)sizeForRect:(CGRect)aRect
21292144 result.height = maxY - (viewFrame.origin .y + viewFrame.size .height );
21302145 result.height -= arrowHeight;
21312146 }
2147+ else if (arrowDirection == WYPopoverArrowDirectionNone)
2148+ {
2149+ result.width = maxX - minX;
2150+ result.height = maxY - minY;
2151+ }
21322152
21332153 return result;
21342154}
0 commit comments