forked from BigShow1949/BigShow1949
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0269834
commit e04ed71
Showing
23 changed files
with
784 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+6.41 KB
(100%)
...xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
BigShow1949/Classes/UIKit/UIDynamic/弹簧效果(CADisplayLink)/Animator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
84 changes: 84 additions & 0 deletions
84
BigShow1949/Classes/UIKit/UIDynamic/弹簧效果(CADisplayLink)/Animator.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
15 changes: 15 additions & 0 deletions
15
BigShow1949/Classes/UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTAppDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
23 changes: 23 additions & 0 deletions
23
BigShow1949/Classes/UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTAppDelegate.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
27 changes: 27 additions & 0 deletions
27
BigShow1949/Classes/UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTDraggableView.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
42 changes: 42 additions & 0 deletions
42
BigShow1949/Classes/UIKit/UIDynamic/弹簧效果(CADisplayLink)/UINTDraggableView.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.