Skip to content

Commit 5a0ef73

Browse files
fix issue #69
1 parent 97a86e3 commit 5a0ef73

2 files changed

Lines changed: 46 additions & 21 deletions

File tree

WYPopoverController/WYPopoverController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ typedef NS_OPTIONS(NSUInteger, WYPopoverAnimationOptions) {
146146
//
147147

148148
- (void)dismissPopoverAnimated:(BOOL)animated;
149+
- (void)dismissPopoverAnimated:(BOOL)animated options:(WYPopoverAnimationOptions)aOptions;
149150

150151
@end
151152

WYPopoverController/WYPopoverController.m

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ of this software and associated documentation files (the "Software"), to deal
3232
#endif
3333

3434
#ifdef DEBUG
35-
#define WY_LOG(fmt, ...) NSLog((@"%s (%d) : " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
35+
#define WY_LOG(fmt, ...) NSLog((@"%s (%d) : " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
3636
#else
3737
#define WY_LOG(...)
3838
#endif
@@ -511,17 +511,17 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
511511

512512
- (BOOL)isPassthroughView:(UIView *)view
513513
{
514-
if (view == nil)
514+
if (view == nil)
515515
{
516-
return NO;
517-
}
518-
519-
if ([self.passthroughViews containsObject:view])
516+
return NO;
517+
}
518+
519+
if ([self.passthroughViews containsObject:view])
520520
{
521-
return YES;
522-
}
523-
524-
return [self isPassthroughView:view.superview];
521+
return YES;
522+
}
523+
524+
return [self isPassthroughView:view.superview];
525525
}
526526

527527
@end
@@ -1345,7 +1345,7 @@ @interface WYPopoverController () <WYPopoverOverlayViewDelegate>
13451345

13461346
@property (nonatomic, assign, readonly) CGSize contentSizeForViewInPopover;
13471347

1348-
- (void)dismissPopoverAnimated:(BOOL)animated callDelegate:(BOOL)callDelegate;
1348+
- (void)dismissPopoverAnimated:(BOOL)animated callDelegate:(BOOL)callDelegate options:(WYPopoverAnimationOptions)options;
13491349

13501350
- (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
13511351
inView:(UIView*)aView
@@ -2047,16 +2047,23 @@ - (void)positionPopover
20472047

20482048
- (void)dismissPopoverAnimated:(BOOL)aAnimated
20492049
{
2050-
[self dismissPopoverAnimated:aAnimated callDelegate:NO];
2050+
[self dismissPopoverAnimated:aAnimated callDelegate:NO options:options];
20512051
}
20522052

2053-
- (void)dismissPopoverAnimated:(BOOL)aAnimated callDelegate:(BOOL)callDelegate
2053+
- (void)dismissPopoverAnimated:(BOOL)aAnimated options:(WYPopoverAnimationOptions)aOptions
2054+
{
2055+
[self dismissPopoverAnimated:aAnimated callDelegate:NO options:aOptions];
2056+
}
2057+
2058+
- (void)dismissPopoverAnimated:(BOOL)aAnimated callDelegate:(BOOL)callDelegate options:(WYPopoverAnimationOptions)aOptions
20542059
{
20552060
if (overlayView == nil) return;
20562061

20572062
void (^completionBlock)(BOOL);
20582063

20592064
CGFloat duration = self.animationDuration;
2065+
WYPopoverAnimationOptions style = aOptions;
2066+
20602067
__weak __typeof__(self) weakSelf = self;
20612068

20622069
completionBlock = ^(BOOL finished) {
@@ -2070,12 +2077,19 @@ - (void)dismissPopoverAnimated:(BOOL)aAnimated callDelegate:(BOOL)callDelegate
20702077
strongSelf->overlayView.alpha = 0;
20712078
} completion:^(BOOL finished) {
20722079
__typeof__(self) strongSelf = weakSelf;
2080+
2081+
[strongSelf->containerView removeFromSuperview];
2082+
strongSelf->containerView = nil;
2083+
20732084
[strongSelf->overlayView removeFromSuperview];
20742085
strongSelf->overlayView = nil;
20752086
}];
20762087
}
20772088
else
20782089
{
2090+
[strongSelf->containerView removeFromSuperview];
2091+
strongSelf->containerView = nil;
2092+
20792093
[strongSelf->overlayView removeFromSuperview];
20802094
strongSelf->overlayView = nil;
20812095
}
@@ -2123,11 +2137,21 @@ - (void)dismissPopoverAnimated:(BOOL)aAnimated callDelegate:(BOOL)callDelegate
21232137

21242138
if (aAnimated)
21252139
{
2126-
CGFloat duration = self.animationDuration;
2127-
21282140
[UIView animateWithDuration:duration animations:^{
21292141
__typeof__(self) strongSelf = weakSelf;
2130-
strongSelf->containerView.alpha = 0;
2142+
2143+
if ((style & WYPopoverAnimationOptionFade) == WYPopoverAnimationOptionFade)
2144+
{
2145+
strongSelf->containerView.alpha = 0;
2146+
}
2147+
2148+
if ((style & WYPopoverAnimationOptionScale) == WYPopoverAnimationOptionScale)
2149+
{
2150+
CGAffineTransform endTransform = [self transformTranslateForArrowDirection:strongSelf->containerView.arrowDirection];
2151+
endTransform = CGAffineTransformScale(endTransform, 0.1, 0.1);
2152+
strongSelf->containerView.transform = endTransform;
2153+
}
2154+
21312155
} completion:^(BOOL finished) {
21322156
completionBlock(finished);
21332157
}];
@@ -2155,7 +2179,7 @@ - (void)popoverOverlayView:(WYPopoverOverlayView *)aOverlayView didTouchAtPoint:
21552179

21562180
if (shouldDismiss)
21572181
{
2158-
[self dismissPopoverAnimated:animated callDelegate:YES];
2182+
[self dismissPopoverAnimated:animated callDelegate:YES options:options];
21592183
}
21602184
}
21612185
}
@@ -2227,8 +2251,8 @@ - (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
22272251
}
22282252

22292253
[areas sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
2230-
WYPopoverArea* area1 = (WYPopoverArea*)obj1;
2231-
WYPopoverArea* area2 = (WYPopoverArea*)obj2;
2254+
WYPopoverArea *area1 = (WYPopoverArea *)obj1;
2255+
WYPopoverArea *area2 = (WYPopoverArea *)obj2;
22322256

22332257
CGFloat val1 = area1.value;
22342258
CGFloat val2 = area2.value;
@@ -2249,7 +2273,7 @@ - (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
22492273

22502274
for (NSUInteger i = 0; i < [areas count]; i++)
22512275
{
2252-
WYPopoverArea* popoverArea = (WYPopoverArea*)[areas objectAtIndex:i];
2276+
WYPopoverArea *popoverArea = (WYPopoverArea *)[areas objectAtIndex:i];
22532277

22542278
if (popoverArea.areaSize.width >= contentSize.width)
22552279
{
@@ -2262,7 +2286,7 @@ - (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
22622286
{
22632287
if ([areas count] > 0)
22642288
{
2265-
arrowDirection = ((WYPopoverArea*)[areas objectAtIndex:0]).arrowDirection;
2289+
arrowDirection = ((WYPopoverArea *)[areas objectAtIndex:0]).arrowDirection;
22662290
}
22672291
else
22682292
{

0 commit comments

Comments
 (0)