Pullable View Like Notification Center Bounces

血红的双手。 提交于 2019-12-23 05:46:45

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!