问题
I have created Pullable view with Pan Gesture every thing working fine but there is a problem with bounces. When we swipe up the view there as to be bounces at end of animation same like Notification Center bounces at the end of view animation. i have created a bounces Category for Bounces but iam not getting same bounces as Notification Center. the has to be Some Tuning on Bounces. So please help me. Below is my Code.
#import "UIView+Bounce.h"
@implementation UIView (Bounce)
+ (CAKeyframeAnimation *)dockBounceAnimationWithViewHeight:(CGFloat)viewHeight {
NSUInteger const kNumFactors = 23;
CGFloat const kFactorsPerSec = 120.0f;
CGFloat const kFactorsMaxValue = 128.0f;
CGFloat factors[kNumFactors] = { 0, 83, 100, 114, 124, 138, 156, 184, 156, 138, 124, 114, 100, 83, 32, 0, 0, 18, 28, 32, 28, 18, 0 };
NSMutableArray *transforms = [NSMutableArray array];
for (NSUInteger i = 0; i < kNumFactors; i++) {
CGFloat positionOffset = factors[i] / kFactorsMaxValue * viewHeight;
CATransform3D transform = CATransform3DMakeTranslation(0.0f, -positionOffset, 0.0f);
[transforms addObject:[NSValue valueWithCATransform3D:transform]];
}
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.repeatCount = 1;
animation.duration = kNumFactors * 1.0f / kFactorsPerSec;
animation.fillMode = kCAFillModeForwards;
animation.values = transforms;
animation.removedOnCompletion = YES; // final stage is equal to starting stage
animation.autoreverses = NO;
return animation;
}
- (void)bounce:(float)bounceFactor {
CGFloat midHeight = self.frame.size.height * bounceFactor;
CAKeyframeAnimation *animation = [[self class] dockBounceAnimationWithViewHeight:midHeight];
[self.layer addAnimation:animation forKey:@"bouncing"];
}
@end
回答1:
Are you targeting iOS7+? In that case the functionality is built in. You can use:
+ (void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
usingSpringWithDamping:(CGFloat)dampingRatio
initialSpringVelocity:(CGFloat)velocity
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
The documentation for that method is here, and basically it's a simple way of making bouncing animations.
The way we do it is that we use the bounces on iOS7+ and on iOS6 we do another kind of animation.
来源:https://stackoverflow.com/questions/24904620/pullable-view-like-notification-center-bounces