Skip to content

Commit fc51142

Browse files
committed
Merge branch 'merge' into barz-master
2 parents 210966f + ce53a24 commit fc51142

2 files changed

Lines changed: 74 additions & 34 deletions

File tree

WYPopoverController/WYPopoverController.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ typedef NS_OPTIONS(NSUInteger, WYPopoverAnimationOptions) {
9696

9797
@property (nonatomic, weak) id <WYPopoverControllerDelegate> delegate;
9898

99-
@property (nonatomic, copy) NSArray *passthroughViews;
100-
@property (nonatomic, assign) BOOL wantsDefaultContentAppearance;
101-
@property (nonatomic, assign) UIEdgeInsets popoverLayoutMargins;
102-
@property (nonatomic, assign, readonly, getter=isPopoverVisible) BOOL popoverVisible;
103-
@property (nonatomic, strong, readonly) UIViewController *contentViewController;
104-
@property (nonatomic, assign) CGSize popoverContentSize;
105-
@property (nonatomic, assign) CGFloat animationDuration;
99+
@property (nonatomic, copy) NSArray *passthroughViews;
100+
@property (nonatomic, assign) BOOL wantsDefaultContentAppearance;
101+
@property (nonatomic, assign) UIEdgeInsets popoverLayoutMargins;
102+
@property (nonatomic, readonly, getter=isPopoverVisible) BOOL popoverVisible;
103+
@property (nonatomic, strong, readonly) UIViewController *contentViewController;
104+
@property (nonatomic, assign) CGSize popoverContentSize;
105+
@property (nonatomic, assign) CGFloat animationDuration;
106106

107107
- (id)initWithContentViewController:(UIViewController *)viewController;
108108

@@ -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: 66 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -1614,15 +1614,20 @@ - (void)presentPopoverFromRect:(CGRect)aRect
16141614
startTransform = CGAffineTransformScale(startTransform, 0.1, 0.1);
16151615
containerView.transform = startTransform;
16161616
}
1617+
1618+
__weak __typeof__(self) weakSelf = self;
16171619

16181620
[UIView animateWithDuration:animationDuration animations:^{
1619-
self->overlayView.alpha = 1;
1620-
self->containerView.alpha = 1;
1621-
self->containerView.transform = endTransform;
1621+
__typeof__(self) strongSelf = weakSelf;
1622+
strongSelf->overlayView.alpha = 1;
1623+
strongSelf->containerView.alpha = 1;
1624+
strongSelf->containerView.transform = endTransform;
16221625
} completion:^(BOOL finished) {
1623-
if ([self->viewController isKindOfClass:[UINavigationController class]] == NO)
1626+
__typeof__(self) strongSelf = weakSelf;
1627+
1628+
if ([strongSelf->viewController isKindOfClass:[UINavigationController class]] == NO)
16241629
{
1625-
[self->viewController viewDidAppear:YES];
1630+
[strongSelf->viewController viewDidAppear:YES];
16261631
}
16271632

16281633
if (completion)
@@ -2042,42 +2047,63 @@ - (void)positionPopover
20422047

20432048
- (void)dismissPopoverAnimated:(BOOL)aAnimated
20442049
{
2045-
[self dismissPopoverAnimated:aAnimated callDelegate:NO];
2050+
[self dismissPopoverAnimated:aAnimated callDelegate:NO options:options];
2051+
}
2052+
2053+
- (void)dismissPopoverAnimated:(BOOL)aAnimated options:(WYPopoverAnimationOptions)aOptions
2054+
{
2055+
[self dismissPopoverAnimated:aAnimated callDelegate:NO options:aOptions];
20462056
}
20472057

2048-
- (void)dismissPopoverAnimated:(BOOL)aAnimated callDelegate:(BOOL)callDelegate
2058+
- (void)dismissPopoverAnimated:(BOOL)aAnimated callDelegate:(BOOL)callDelegate options:(WYPopoverAnimationOptions)aOptions
20492059
{
20502060
if (overlayView == nil) return;
20512061

20522062
void (^completionBlock)(BOOL);
2053-
2063+
2064+
CGFloat duration = self.animationDuration;
2065+
WYPopoverAnimationOptions style = aOptions;
2066+
2067+
__weak __typeof__(self) weakSelf = self;
2068+
20542069
completionBlock = ^(BOOL finished) {
2070+
2071+
__typeof__(self) strongSelf = weakSelf;
20552072

20562073
if (aAnimated)
20572074
{
2058-
[UIView animateWithDuration:self->animationDuration animations:^{
2059-
self->overlayView.alpha = 0;
2060-
} completion:^(BOOL finished1) {
2061-
[self->overlayView removeFromSuperview];
2062-
self->overlayView = nil;
2075+
[UIView animateWithDuration:duration animations:^{
2076+
__typeof__(self) strongSelf = weakSelf;
2077+
strongSelf->overlayView.alpha = 0;
2078+
} completion:^(BOOL finished) {
2079+
__typeof__(self) strongSelf = weakSelf;
2080+
2081+
[strongSelf->containerView removeFromSuperview];
2082+
strongSelf->containerView = nil;
2083+
2084+
[strongSelf->overlayView removeFromSuperview];
2085+
strongSelf->overlayView = nil;
20632086
}];
20642087
}
20652088
else
20662089
{
2067-
[self->overlayView removeFromSuperview];
2068-
self->overlayView = nil;
2090+
[strongSelf->containerView removeFromSuperview];
2091+
strongSelf->containerView = nil;
2092+
2093+
[strongSelf->overlayView removeFromSuperview];
2094+
strongSelf->overlayView = nil;
20692095
}
20702096

2071-
if ([self->viewController isKindOfClass:[UINavigationController class]] == NO)
2097+
if ([strongSelf->viewController isKindOfClass:[UINavigationController class]] == NO)
20722098
{
2073-
[self->viewController viewDidDisappear:aAnimated];
2099+
[strongSelf->viewController viewDidDisappear:aAnimated];
20742100
}
20752101

20762102
if (callDelegate)
20772103
{
2078-
if (self->delegate && [self->delegate respondsToSelector:@selector(popoverControllerDidDismissPopover:)])
2104+
if (strongSelf->delegate && [strongSelf->delegate respondsToSelector:@selector(popoverControllerDidDismissPopover:)])
20792105
{
2080-
[self->delegate popoverControllerDidDismissPopover:self];
2106+
[strongSelf->delegate popoverControllerDidDismissPopover:strongSelf];
20812107
}
20822108
}
20832109
};
@@ -2111,8 +2137,21 @@ - (void)dismissPopoverAnimated:(BOOL)aAnimated callDelegate:(BOOL)callDelegate
21112137

21122138
if (aAnimated)
21132139
{
2114-
[UIView animateWithDuration:animationDuration animations:^{
2115-
self->containerView.alpha = 0;
2140+
[UIView animateWithDuration:duration animations:^{
2141+
__typeof__(self) strongSelf = weakSelf;
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+
21162155
} completion:^(BOOL finished) {
21172156
completionBlock(finished);
21182157
}];
@@ -2140,7 +2179,7 @@ - (void)popoverOverlayView:(WYPopoverOverlayView *)aOverlayView didTouchAtPoint:
21402179

21412180
if (shouldDismiss)
21422181
{
2143-
[self dismissPopoverAnimated:animated callDelegate:YES];
2182+
[self dismissPopoverAnimated:animated callDelegate:YES options:options];
21442183
}
21452184
}
21462185
}
@@ -2212,8 +2251,8 @@ - (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
22122251
}
22132252

22142253
[areas sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
2215-
WYPopoverArea* area1 = (WYPopoverArea*)obj1;
2216-
WYPopoverArea* area2 = (WYPopoverArea*)obj2;
2254+
WYPopoverArea *area1 = (WYPopoverArea *)obj1;
2255+
WYPopoverArea *area2 = (WYPopoverArea *)obj2;
22172256

22182257
CGFloat val1 = area1.value;
22192258
CGFloat val2 = area2.value;
@@ -2234,7 +2273,7 @@ - (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
22342273

22352274
for (NSUInteger i = 0; i < [areas count]; i++)
22362275
{
2237-
WYPopoverArea* popoverArea = (WYPopoverArea*)[areas objectAtIndex:i];
2276+
WYPopoverArea *popoverArea = (WYPopoverArea *)[areas objectAtIndex:i];
22382277

22392278
if (popoverArea.areaSize.width >= contentSize.width)
22402279
{
@@ -2247,7 +2286,7 @@ - (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
22472286
{
22482287
if ([areas count] > 0)
22492288
{
2250-
arrowDirection = ((WYPopoverArea*)[areas objectAtIndex:0]).arrowDirection;
2289+
arrowDirection = ((WYPopoverArea *)[areas objectAtIndex:0]).arrowDirection;
22512290
}
22522291
else
22532292
{

0 commit comments

Comments
 (0)