diff --git a/WYPopoverController/WYPopoverController.h b/WYPopoverController/WYPopoverController.h index 25f23381..638a7605 100644 --- a/WYPopoverController/WYPopoverController.h +++ b/WYPopoverController/WYPopoverController.h @@ -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 @@ -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; diff --git a/WYPopoverController/WYPopoverController.m b/WYPopoverController/WYPopoverController.m index fecbce90..39a384da 100644 --- a/WYPopoverController/WYPopoverController.m +++ b/WYPopoverController/WYPopoverController.m @@ -1595,6 +1595,8 @@ @implementation WYPopoverController @synthesize popoverLayoutMargins; @synthesize popoverContentSize = popoverContentSize_; @synthesize animationDuration; +@synthesize animationDampingRatio; +@synthesize animationInitialVelocity; @synthesize theme; static WYPopoverTheme *defaultTheme_ = nil; @@ -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; @@ -1998,7 +2002,7 @@ - (void)presentPopoverFromRect:(CGRect)aRect backgroundView.transform = startTransform; } - [UIView animateWithDuration:animationDuration animations:^{ + void (^animationBlock)() = ^() { __typeof__(self) strongSelf = weakSelf; if (strongSelf) @@ -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 { diff --git a/demos/Demo/WYPopoverDemo/WYAllDirectionsViewController.m b/demos/Demo/WYPopoverDemo/WYAllDirectionsViewController.m index 6a3cd657..c77217d1 100644 --- a/demos/Demo/WYPopoverDemo/WYAllDirectionsViewController.m +++ b/demos/Demo/WYPopoverDemo/WYAllDirectionsViewController.m @@ -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