Skip to content

Commit

Permalink
弹簧效果
Browse files Browse the repository at this point in the history
  • Loading branch information
BigShow1949 committed Aug 25, 2016
1 parent 0269834 commit e04ed71
Show file tree
Hide file tree
Showing 23 changed files with 784 additions and 2 deletions.
Binary file modified .svn/wc.db
Binary file not shown.
72 changes: 72 additions & 0 deletions BigShow1949.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@
186E63361D6EA5060070A717 /* YFCollisionBehaviorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E63341D6EA5060070A717 /* YFCollisionBehaviorViewController.m */; };
186E63371D6EA5060070A717 /* YFCollisionBehaviorViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 186E63351D6EA5060070A717 /* YFCollisionBehaviorViewController.storyboard */; };
186E633B1D6EC60C0070A717 /* YFDynamicItemViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E633A1D6EC60C0070A717 /* YFDynamicItemViewController.m */; };
186E63521D6EE18D0070A717 /* DraggableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E634B1D6EE18D0070A717 /* DraggableView.m */; };
186E63531D6EE18D0070A717 /* PaneBehavior.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E634D1D6EE18D0070A717 /* PaneBehavior.m */; };
186E63541D6EE18D0070A717 /* YFFlexView.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E634F1D6EE18D0070A717 /* YFFlexView.m */; };
186E63551D6EE18D0070A717 /* YFFlexViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E63511D6EE18D0070A717 /* YFFlexViewController.m */; };
186E63621D6EE1BB0070A717 /* Animator.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E63581D6EE1BB0070A717 /* Animator.m */; };
186E63631D6EE1BB0070A717 /* UINTAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E635A1D6EE1BB0070A717 /* UINTAppDelegate.m */; };
186E63641D6EE1BB0070A717 /* UINTViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E635C1D6EE1BB0070A717 /* UINTViewController.m */; };
186E63651D6EE1BB0070A717 /* UINTDraggableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E635D1D6EE1BB0070A717 /* UINTDraggableView.m */; };
186E63661D6EE1BB0070A717 /* UINTSpringAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = 186E63601D6EE1BB0070A717 /* UINTSpringAnimation.m */; };
189242651B99D065008AC1EB /* YFAuthorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 189242641B99D065008AC1EB /* YFAuthorViewController.m */; };
18C2D5331BAEDC98006CD3B2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18C2D5311BAEDC61006CD3B2 /* UIKit.framework */; };
18C2D5361BAEDCC8006CD3B2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18C2D5341BAEDCAC006CD3B2 /* Foundation.framework */; };
Expand Down Expand Up @@ -697,6 +706,25 @@
186E63351D6EA5060070A717 /* YFCollisionBehaviorViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = YFCollisionBehaviorViewController.storyboard; sourceTree = "<group>"; };
186E63391D6EC60C0070A717 /* YFDynamicItemViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YFDynamicItemViewController.h; sourceTree = "<group>"; };
186E633A1D6EC60C0070A717 /* YFDynamicItemViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YFDynamicItemViewController.m; sourceTree = "<group>"; };
186E634A1D6EE18D0070A717 /* DraggableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DraggableView.h; sourceTree = "<group>"; };
186E634B1D6EE18D0070A717 /* DraggableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DraggableView.m; sourceTree = "<group>"; };
186E634C1D6EE18D0070A717 /* PaneBehavior.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PaneBehavior.h; sourceTree = "<group>"; };
186E634D1D6EE18D0070A717 /* PaneBehavior.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PaneBehavior.m; sourceTree = "<group>"; };
186E634E1D6EE18D0070A717 /* YFFlexView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YFFlexView.h; sourceTree = "<group>"; };
186E634F1D6EE18D0070A717 /* YFFlexView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YFFlexView.m; sourceTree = "<group>"; };
186E63501D6EE18D0070A717 /* YFFlexViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YFFlexViewController.h; sourceTree = "<group>"; };
186E63511D6EE18D0070A717 /* YFFlexViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YFFlexViewController.m; sourceTree = "<group>"; };
186E63571D6EE1BB0070A717 /* Animator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Animator.h; sourceTree = "<group>"; };
186E63581D6EE1BB0070A717 /* Animator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Animator.m; sourceTree = "<group>"; };
186E63591D6EE1BB0070A717 /* UINTAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UINTAppDelegate.h; sourceTree = "<group>"; };
186E635A1D6EE1BB0070A717 /* UINTAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UINTAppDelegate.m; sourceTree = "<group>"; };
186E635B1D6EE1BB0070A717 /* UINTViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UINTViewController.h; sourceTree = "<group>"; };
186E635C1D6EE1BB0070A717 /* UINTViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UINTViewController.m; sourceTree = "<group>"; };
186E635D1D6EE1BB0070A717 /* UINTDraggableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UINTDraggableView.m; sourceTree = "<group>"; };
186E635E1D6EE1BB0070A717 /* UINTDraggableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UINTDraggableView.h; sourceTree = "<group>"; };
186E635F1D6EE1BB0070A717 /* UINTGeometryExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UINTGeometryExtras.h; sourceTree = "<group>"; };
186E63601D6EE1BB0070A717 /* UINTSpringAnimation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UINTSpringAnimation.m; sourceTree = "<group>"; };
186E63611D6EE1BB0070A717 /* UINTSpringAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UINTSpringAnimation.h; sourceTree = "<group>"; };
189242631B99D065008AC1EB /* YFAuthorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YFAuthorViewController.h; sourceTree = "<group>"; };
189242641B99D065008AC1EB /* YFAuthorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YFAuthorViewController.m; sourceTree = "<group>"; };
18C2D5311BAEDC61006CD3B2 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -1959,6 +1987,8 @@
children = (
186E631B1D6E868B0070A717 /* YFDynamicViewController.h */,
186E631C1D6E868B0070A717 /* YFDynamicViewController.m */,
186E63561D6EE1A40070A717 /* 弹簧效果(CADisplayLink) */,
186E63491D6EE18D0070A717 /* 弹簧效果(附着行为) */,
186E63381D6EC5F50070A717 /* 动力元素行为 */,
186E632F1D6EA3130070A717 /* 附着行为 */,
186E63281D6E99AD0070A717 /* 推动行为 */,
Expand Down Expand Up @@ -2014,6 +2044,39 @@
path = "动力元素行为";
sourceTree = "<group>";
};
186E63491D6EE18D0070A717 /* 弹簧效果(附着行为) */ = {
isa = PBXGroup;
children = (
186E634A1D6EE18D0070A717 /* DraggableView.h */,
186E634B1D6EE18D0070A717 /* DraggableView.m */,
186E634C1D6EE18D0070A717 /* PaneBehavior.h */,
186E634D1D6EE18D0070A717 /* PaneBehavior.m */,
186E634E1D6EE18D0070A717 /* YFFlexView.h */,
186E634F1D6EE18D0070A717 /* YFFlexView.m */,
186E63501D6EE18D0070A717 /* YFFlexViewController.h */,
186E63511D6EE18D0070A717 /* YFFlexViewController.m */,
);
path = "弹簧效果(附着行为)";
sourceTree = "<group>";
};
186E63561D6EE1A40070A717 /* 弹簧效果(CADisplayLink) */ = {
isa = PBXGroup;
children = (
186E63571D6EE1BB0070A717 /* Animator.h */,
186E63581D6EE1BB0070A717 /* Animator.m */,
186E63591D6EE1BB0070A717 /* UINTAppDelegate.h */,
186E635A1D6EE1BB0070A717 /* UINTAppDelegate.m */,
186E635B1D6EE1BB0070A717 /* UINTViewController.h */,
186E635C1D6EE1BB0070A717 /* UINTViewController.m */,
186E635D1D6EE1BB0070A717 /* UINTDraggableView.m */,
186E635E1D6EE1BB0070A717 /* UINTDraggableView.h */,
186E635F1D6EE1BB0070A717 /* UINTGeometryExtras.h */,
186E63601D6EE1BB0070A717 /* UINTSpringAnimation.m */,
186E63611D6EE1BB0070A717 /* UINTSpringAnimation.h */,
);
path = "弹簧效果(CADisplayLink)";
sourceTree = "<group>";
};
18C2D52F1BAEDC2C006CD3B2 /* Framework */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4456,6 +4519,8 @@
B87042601CAB7CEB0067653C /* YFResizableView.m in Sources */,
8BC4AD901B9682B00026B012 /* MJRefreshHeaderView.m in Sources */,
B88A15511CA393F400BFC377 /* Case7ViewController.m in Sources */,
186E63651D6EE1BB0070A717 /* UINTDraggableView.m in Sources */,
186E63661D6EE1BB0070A717 /* UINTSpringAnimation.m in Sources */,
185C98AC1D67E6EC00955C5F /* UILabel+BezierAnimation.m in Sources */,
185C991F1D67F0A500955C5F /* YFKnowledgeVC02.m in Sources */,
8BC4AD4C1B9681B70026B012 /* SDWebImageDownloaderOperation.m in Sources */,
Expand All @@ -4476,6 +4541,7 @@
181F28AF1D2CF53C00FC2637 /* UILabel+Associate.m in Sources */,
B891DAE91CA11ABB007F69AF /* MASConstraint.m in Sources */,
B8763CE01C980EA8007B200B /* RGCardViewLayout.m in Sources */,
186E63541D6EE18D0070A717 /* YFFlexView.m in Sources */,
B891DAE81CA11ABB007F69AF /* MASCompositeConstraint.m in Sources */,
B87042A11CABCDFE0067653C /* JLHomePracticeViewController.m in Sources */,
181F28A31D2CEF1600FC2637 /* Classes.m in Sources */,
Expand Down Expand Up @@ -4557,6 +4623,7 @@
B891D9F31CA0F7A9007F69AF /* RZZoomAlphaAnimationController.m in Sources */,
B869D5391C46406600233328 /* YFBlogViewController.m in Sources */,
B89386511C9FCE5A00B122B8 /* HHHorizontalPagingView.m in Sources */,
186E63531D6EE18D0070A717 /* PaneBehavior.m in Sources */,
8BC4AD481B9681B70026B012 /* SDImageCache.m in Sources */,
185C99231D67F0A500955C5F /* MyItem.m in Sources */,
18CAD0861B9977E3001066FF /* YFDragRadialMenu.m in Sources */,
Expand All @@ -4570,6 +4637,7 @@
B891D9F21CA0F7A9007F69AF /* RZShrinkZoomAnimationController.m in Sources */,
B852D5721C52315200454E7F /* YFNeteaseViewController.m in Sources */,
185C99271D67F0A500955C5F /* SecondViewController.m in Sources */,
186E63631D6EE1BB0070A717 /* UINTAppDelegate.m in Sources */,
185C992B1D67F0A500955C5F /* YFTableViewDelAllCell.m in Sources */,
184B38531D2521A8005CD7F1 /* ModelOne.m in Sources */,
B88A15531CA393F400BFC377 /* Case8DataEntity.m in Sources */,
Expand All @@ -4579,6 +4647,7 @@
185C98AE1D67E6EC00955C5F /* YFAliNumberViewController.m in Sources */,
B84C03361CE317DE00E62D75 /* ITRSecondViewController.m in Sources */,
18CAD07A1B9977E3001066FF /* YFItemView.m in Sources */,
186E63641D6EE1BB0070A717 /* UINTViewController.m in Sources */,
B83EA95C1CC0C74C00807828 /* FMDatabasePool.m in Sources */,
B852D5261C51D61900454E7F /* YFCoreAnimationViewController.m in Sources */,
B88023001CAE5B2D002C0021 /* UIImage+CJZ.m in Sources */,
Expand Down Expand Up @@ -4684,6 +4753,7 @@
B88022FD1CAE291D002C0021 /* YFImageCategoryViewController.m in Sources */,
B891D9ED1CA0F7A9007F69AF /* RZTransitionsManager.m in Sources */,
18CAD0D31B998A93001066FF /* YFSnowViewController.m in Sources */,
186E63621D6EE1BB0070A717 /* Animator.m in Sources */,
8BC4AD891B9682B00026B012 /* NSObject+MJCoding.m in Sources */,
185C990D1D67F0A500955C5F /* SYArenaViewController.m in Sources */,
8BC4AD861B9682B00026B012 /* MJMethod.m in Sources */,
Expand All @@ -4694,6 +4764,7 @@
B864C7791C99035D00D1E440 /* DeformationButton.m in Sources */,
B8729E801C9A54F200A18AA5 /* LTSlidingViewCoverflowTransition.m in Sources */,
18CAD0851B9977E3001066FF /* YFAnimationVC06.m in Sources */,
186E63551D6EE18D0070A717 /* YFFlexViewController.m in Sources */,
B80E93931CC8785D00607EF3 /* DataAlterFieldView.m in Sources */,
B8D444331C50B86200F3A34E /* UPStackMenuItem.m in Sources */,
B8763CE21C980EA8007B200B /* RGCollectionViewCell.m in Sources */,
Expand Down Expand Up @@ -4764,6 +4835,7 @@
B87042611CAB7CEB0067653C /* YFAnswerNaviBar.m in Sources */,
1804225F1D6D782A009CB5AC /* UITextField+Shake.m in Sources */,
B85C96C11C4F83F50096E2A1 /* XXBRippleView.m in Sources */,
186E63521D6EE18D0070A717 /* DraggableView.m in Sources */,
B893865B1C9FCE6300B122B8 /* HHHeaderView.m in Sources */,
B891D9E61CA0F7A9007F69AF /* RZTransitionsNavigationController.m in Sources */,
B87446001CAD2289009F274E /* YFColorViewController.m in Sources */,
Expand Down
Binary file not shown.
8 changes: 6 additions & 2 deletions BigShow1949/Classes/UIKit/UIDynamic/YFDynamicViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ - (void)viewDidLoad {
@"捕捉行为",
@"推动行为",
@"附着行为",
@"动力元素行为"];
@"动力元素行为",
@"弹簧效果(附着行为)",
@"弹簧效果(CADisplayLink)"];

self.classNames = @[@"YFCollisionBehaviorViewController_UIStoryboard",
@"YFSnapBehaviorViewController",
@"YFPushBehaviorViewController",
@"YFAttachmentBehaviorViewController",
@"YFDynamicItemViewController"];
@"YFDynamicItemViewController",
@"YFFlexViewController",
@"UINTViewController"];

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@protocol Animation <NSObject>
- (void)animationTick:(CFTimeInterval)dt finished:(BOOL *)finished;
@end

@interface Animator : NSObject

+ (instancetype)animatorWithScreen:(UIScreen *)screen;

- (void)addAnimation:(id<Animation>)animatable;
- (void)removeAnimation:(id<Animation>)animatable;

@end

@interface UIView (AnimatorAdditions)

- (Animator *)animator;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#import "Animator.h"
#import <objc/runtime.h>

static int ScreenAnimationDriverKey;

@interface Animator ()

@property (nonatomic, strong) CADisplayLink *displayLink;
@property (nonatomic, strong) NSMutableSet *animations;
@end

@implementation Animator
{
}

+ (instancetype)animatorWithScreen:(UIScreen *)screen
{
if (!screen) {
screen = [UIScreen mainScreen];
}
Animator *driver = objc_getAssociatedObject(screen, &ScreenAnimationDriverKey);
if (!driver) {
driver = [[self alloc] initWithScreen:screen];
objc_setAssociatedObject(screen, &ScreenAnimationDriverKey, driver, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return driver;
}

- (instancetype)initWithScreen:(UIScreen *)screen
{
self = [super init];
if (self) {
self.displayLink = [screen displayLinkWithTarget:self selector:@selector(animationTick:)];
self.displayLink.paused = YES;
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
self.animations = [NSMutableSet new];
}
return self;
}

- (void)addAnimation:(id<Animation>)animation
{
[self.animations addObject:animation];
if (self.animations.count == 1) {
self.displayLink.paused = NO;
}
}

- (void)removeAnimation:(id <Animation>)animatable
{
if (animatable == nil) return;

[self.animations removeObject:animatable];
if (self.animations.count == 0) {
self.displayLink.paused = YES;
}
}


- (void)animationTick:(CADisplayLink *)displayLink
{
CFTimeInterval dt = displayLink.duration;
for (id<Animation> a in [self.animations copy]) {
BOOL finished = NO;
[a animationTick:dt finished:&finished];
if (finished) {
[self.animations removeObject:a];
}
}
if (self.animations.count == 0) {
self.displayLink.paused = YES;
}
}

@end

@implementation UIView (AnimatorAdditions)

- (Animator *)animator
{
return [Animator animatorWithScreen:self.window.screen];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// UINTAppDelegate.h
// InteractiveAnimations
//
// Created by Chris Eidhof on 02.05.14.
// Copyright (c) 2014 Unsigned Integer. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UINTAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// UINTAppDelegate.m
// InteractiveAnimations
//
// Created by Chris Eidhof on 02.05.14.
// Copyright (c) 2014 Unsigned Integer. All rights reserved.
//

#import "UINTAppDelegate.h"
#import "UINTViewController.h"

@implementation UINTAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINTViewController *viewController = [[UINTViewController alloc] init];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Created by Florian on 21/04/14.
//
// To change the template use AppCode | Preferences | File Templates.
//


#import <Foundation/Foundation.h>
#import "Animator.h"


@class UINTDraggableView;


@protocol DraggableViewDelegate

- (void)draggableView:(UINTDraggableView *)view draggingEndedWithVelocity:(CGPoint)velocity;
- (void)draggableViewBeganDragging:(UINTDraggableView *)view;

@end


@interface UINTDraggableView : UIView

@property (nonatomic, weak) id <DraggableViewDelegate> delegate;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Created by Florian on 21/04/14.
//
// To change the template use AppCode | Preferences | File Templates.
//


#import "UINTDraggableView.h"

@implementation UINTDraggableView

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}

- (void)setup
{
UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
[self addGestureRecognizer:recognizer];
self.layer.cornerRadius = 6;
}

- (void)didPan:(UIPanGestureRecognizer *)recognizer
{
CGPoint point = [recognizer translationInView:self.superview];
self.center = CGPointMake(self.center.x, self.center.y + point.y);
[recognizer setTranslation:CGPointZero inView:self.superview];
if (recognizer.state == UIGestureRecognizerStateEnded) {
CGPoint velocity = [recognizer velocityInView:self.superview];
velocity.x = 0;
[self.delegate draggableView:self draggingEndedWithVelocity:velocity];
} else if (recognizer.state == UIGestureRecognizerStateBegan) {
[self.delegate draggableViewBeganDragging:self];
}
}

@end
Loading

0 comments on commit e04ed71

Please sign in to comment.