首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pullable Like Notification Center弹回

Pullable Like Notification Center弹回
EN

Stack Overflow用户
提问于 2014-07-23 15:46:02
回答 1查看 429关注 0票数 0

我已经用平移手势创建了可拉动的视图,一切都很好,但弹跳有个问题。当我们向上滑动视图时,动画结束时会有反弹,就像通知中心在视图动画结束时反弹一样。我已经为退回创建了退回类别,但我没有得到与通知中心相同的退回。这必须对反弹进行一些调整。所以请帮帮我。下面是我的代码。

代码语言:javascript
复制
#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
EN

回答 1

Stack Overflow用户

发布于 2014-07-23 15:54:01

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

代码语言:javascript
复制
+ (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

该方法的文档是here,基本上它是一种制作弹跳动画的简单方法。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24904620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档