Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions WYPopoverController/WYPopoverController.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#define WY_POPOVER_DEFAULT_ANIMATION_DURATION .25f
#endif

#ifndef WY_POPOVER_DEFAULT_ANIMATION_DAMPING_RATIO
#define WY_POPOVER_DEFAULT_ANIMATION_DAMPING_RATIO 1.0f
#endif

#ifndef WY_POPOVER_DEFAULT_ANIMATION_INITIAL_VELOCITY
#define WY_POPOVER_DEFAULT_ANIMATION_INITIAL_VELOCITY 1.0f
#endif

#ifndef WY_POPOVER_MIN_SIZE
#define WY_POPOVER_MIN_SIZE CGSizeMake(240, 160)
#endif
Expand Down Expand Up @@ -102,6 +110,8 @@ typedef NS_OPTIONS(NSUInteger, WYPopoverAnimationOptions) {
@property (nonatomic, strong, readonly) UIViewController *contentViewController;
@property (nonatomic, assign) CGSize popoverContentSize;
@property (nonatomic, assign) float animationDuration;
@property (nonatomic, assign) float animationDampingRatio;
@property (nonatomic, assign) float animationInitialVelocity;

@property (nonatomic, strong) WYPopoverTheme *theme;

Expand Down
26 changes: 22 additions & 4 deletions WYPopoverController/WYPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,8 @@ @implementation WYPopoverController
@synthesize popoverLayoutMargins;
@synthesize popoverContentSize = popoverContentSize_;
@synthesize animationDuration;
@synthesize animationDampingRatio;
@synthesize animationInitialVelocity;
@synthesize theme;

static WYPopoverTheme *defaultTheme_ = nil;
Expand Down Expand Up @@ -1649,6 +1651,8 @@ - (id)init
popoverLayoutMargins = UIEdgeInsetsMake(10, 10, 10, 10);
keyboardRect = CGRectZero;
animationDuration = WY_POPOVER_DEFAULT_ANIMATION_DURATION;
animationDampingRatio = WY_POPOVER_DEFAULT_ANIMATION_DAMPING_RATIO;
animationInitialVelocity = WY_POPOVER_DEFAULT_ANIMATION_INITIAL_VELOCITY;

themeUpdatesEnabled = NO;

Expand Down Expand Up @@ -1998,7 +2002,7 @@ - (void)presentPopoverFromRect:(CGRect)aRect
backgroundView.transform = startTransform;
}

[UIView animateWithDuration:animationDuration animations:^{
void (^animationBlock)() = ^() {
__typeof__(self) strongSelf = weakSelf;

if (strongSelf)
Expand All @@ -2007,9 +2011,23 @@ - (void)presentPopoverFromRect:(CGRect)aRect
strongSelf->backgroundView.alpha = 1;
strongSelf->backgroundView.transform = endTransform;
}
} completion:^(BOOL finished) {
completionBlock(YES);
}];
};

#ifdef WY_BASE_SDK_7_ENABLED
if ((animationInitialVelocity != WY_POPOVER_DEFAULT_ANIMATION_INITIAL_VELOCITY ||
animationDampingRatio != WY_POPOVER_DEFAULT_ANIMATION_DAMPING_RATIO) &&
[UIView respondsToSelector:@selector(animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:)]) {
[UIView animateWithDuration:animationDuration delay:0 usingSpringWithDamping:animationDampingRatio initialSpringVelocity:animationInitialVelocity options:0 animations:animationBlock completion:^(BOOL finished) {
completionBlock(YES);
}];
} else {
#endif
[UIView animateWithDuration:animationDuration animations:animationBlock completion:^(BOOL finished) {
completionBlock(YES);
}];
#ifdef WY_BASE_SDK_7_ENABLED
}
#endif
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions demos/Demo/WYPopoverDemo/WYAllDirectionsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ - (IBAction)showpopover:(id)sender
settingsPopoverController.passthroughViews = @[btn];
settingsPopoverController.popoverLayoutMargins = UIEdgeInsetsMake(10, 10, 10, 10);
settingsPopoverController.wantsDefaultContentAppearance = NO;
if (sender == topButton) {
settingsPopoverController.animationDampingRatio = 0.6f;
settingsPopoverController.animationInitialVelocity = 0.0f;
}

[settingsPopoverController presentPopoverFromRect:btn.bounds
inView:btn
Expand Down