像通知中心那样的可拉动视图反弹 [英] Pullable View Like Notification Center Bounces

查看:79
本文介绍了像通知中心那样的可拉动视图反弹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Pan Gesture创建了Pullable视图,但每个工作正常,但跳出有问题。当我们向上滑动视图时,在动画结束时反弹,就像通知中心在视图动画结束时反弹一样。我已经为跳出创建了跳出类别但是我没有像通知中心那样获得相同的反弹。必须在弹跳上进行一些调整。所以请帮助我。下面是我的代码。

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


推荐答案

你的目标是iOS7 +吗?在这种情况下,功能是内置的。您可以使用:

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.

我们这样做的方式是我们使用iOS7 +和iOS6上的反弹另一种动画。

The way we do it is that we use the bounces on iOS7+ and on iOS6 we do another kind of animation.

这篇关于像通知中心那样的可拉动视图反弹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆