Skip to content

Commit

Permalink
Animations are awesome.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmkilger committed Aug 17, 2012
1 parent 7b6bbf6 commit 9a99195
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 169 deletions.
4 changes: 4 additions & 0 deletions Seuss for iPad.xcodeproj/project.pbxproj
Expand Up @@ -30,6 +30,7 @@
9A3E36C815BA74E400C3C268 /* SSCanvasView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A3E36C715BA74E400C3C268 /* SSCanvasView.m */; };
9A3E36CB15BA755E00C3C268 /* SSStatementView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A3E36CA15BA755E00C3C268 /* SSStatementView.m */; };
9A3E36CE15BA758100C3C268 /* SSVariableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A3E36CD15BA758100C3C268 /* SSVariableView.m */; };
9A4EBA1D15DC4DE900A15E33 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A4EBA1C15DC4DE900A15E33 /* QuartzCore.framework */; };
9A599F1015C26B72000DED43 /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 9A599F0E15C26B72000DED43 /* Model.xcdatamodeld */; };
9A599F3915C315E9000DED43 /* SSProgram+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A599F3815C315E9000DED43 /* SSProgram+Additions.m */; };
9A599F4E15C4886B000DED43 /* NSManagedObject+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A599F4D15C4886B000DED43 /* NSManagedObject+Additions.m */; };
Expand Down Expand Up @@ -101,6 +102,7 @@
9A3E36CA15BA755E00C3C268 /* SSStatementView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSStatementView.m; sourceTree = "<group>"; };
9A3E36CC15BA758100C3C268 /* SSVariableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSVariableView.h; sourceTree = "<group>"; };
9A3E36CD15BA758100C3C268 /* SSVariableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSVariableView.m; sourceTree = "<group>"; };
9A4EBA1C15DC4DE900A15E33 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
9A599F0F15C26B72000DED43 /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = "<group>"; };
9A599F3715C315E9000DED43 /* SSProgram+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SSProgram+Additions.h"; sourceTree = "<group>"; };
9A599F3815C315E9000DED43 /* SSProgram+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SSProgram+Additions.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -151,6 +153,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9A4EBA1D15DC4DE900A15E33 /* QuartzCore.framework in Frameworks */,
9A599F8915C50C2E000DED43 /* CoreData.framework in Frameworks */,
9AB784AF15BBC703002CEE23 /* libseuss.a in Frameworks */,
9A3E369215BA745700C3C268 /* UIKit.framework in Frameworks */,
Expand Down Expand Up @@ -217,6 +220,7 @@
9A3E369115BA745700C3C268 /* UIKit.framework */,
9A3E369315BA745700C3C268 /* Foundation.framework */,
9A3E369515BA745700C3C268 /* CoreGraphics.framework */,
9A4EBA1C15DC4DE900A15E33 /* QuartzCore.framework */,
9A599F8815C50C2E000DED43 /* CoreData.framework */,
9A3E36AF15BA745700C3C268 /* SenTestingKit.framework */,
);
Expand Down
39 changes: 24 additions & 15 deletions Seuss for iPad/SSCanvasView.m
Expand Up @@ -204,12 +204,12 @@ - (void)moveStatement:(UIGestureRecognizer *)gesture {

- (void)moveParameter:(UIGestureRecognizer *)gesture {
UIView * view = [gesture view];
CGPoint point = [gesture locationInView:self.mainView];
switch (gesture.state) {
case UIGestureRecognizerStateBegan: {
if (!self.movingParameter) {
UIView * movingView = view;
if ([self.variableViews containsObject:movingView]) {
CGPoint point = [gesture locationInView:self.mainView];
movingView = [[SSVariableView alloc] initWithVariable:[(SSVariableView *)view variable]];
[movingView addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(moveParameter:)]];
[movingView addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveParameter:)]];
Expand All @@ -218,12 +218,17 @@ - (void)moveParameter:(UIGestureRecognizer *)gesture {
movingView.layer.shadowOffset = CGSizeMake(0.0, 1.0);
movingView.layer.shadowRadius = 3.0;
movingView.layer.cornerRadius = 3.0;
movingView.center = point;
[self.mainView addSubview:movingView];
}
else {
// TODO: remove from the statement
SSStatementView * statementView = (SSStatementView *)[movingView superview];
[statementView removeParameterForView:movingView];
movingView.center = [gesture locationInView:statementView];
[[movingView superview] bringSubviewToFront:movingView];
[self.mainView bringSubviewToFront:statementView];
}
movingView.center = point;
[self.mainView addSubview:movingView];
self.movingParameter = movingView;
[UIView animateWithDuration:0.1 animations:^{
movingView.transform = CGAffineTransformMakeScale(1.25, 1.25);
Expand All @@ -234,32 +239,36 @@ - (void)moveParameter:(UIGestureRecognizer *)gesture {
} break;

case UIGestureRecognizerStateChanged: {
self.movingParameter.center = point;
[UIView animateWithDuration:0.2 animations:^{
for (SSStatementView * statementView in self.statementViews) {
if (CGRectContainsPoint(statementView.frame, point))
[statementView prepareForParameterView:self.movingParameter atPoint:[self convertPoint:point toView:statementView]];
else
[statementView unprepare];
UIView * movingView = self.movingParameter;
CGPoint point = [gesture locationInView:[movingView superview]];
movingView.center = point;
for (SSStatementView * statementView in self.statementViews) {
if (CGRectContainsPoint(statementView.frame, [self.mainView convertPoint:point fromView:[movingView superview]])) {
CGPoint statementPoint = [[movingView superview] convertPoint:point toView:statementView];
[statementView prepareForParameterView:movingView atPoint:statementPoint animated:YES];
}
}];
else {
[statementView unprepareAnimated:YES];
}
}
[[movingView superview] bringSubviewToFront:movingView];

} break;

case UIGestureRecognizerStateEnded: {
BOOL added = NO;
UIView * movingView = self.movingParameter;
self.movingParameter = nil;
movingView.alpha = 1.0;
movingView.transform = CGAffineTransformIdentity;
for (SSStatementView * statementView in self.statementViews) {
CGPoint point = [gesture locationInView:self.mainView];
if (CGRectContainsPoint(statementView.frame, point)) {
added = [statementView addParameterView:movingView atPoint:[self convertPoint:point toView:statementView]];
[self.mainView bringSubviewToFront:statementView];
added = [statementView addParameterView:movingView atPoint:[statementView convertPoint:point fromView:self.mainView]];
break;
}
}
if (!added) {
[UIView animateWithDuration:0.1 animations:^{
[UIView animateWithDuration:0.2 animations:^{
movingView.alpha = 0.0;
} completion:^(BOOL finished) {
[movingView removeFromSuperview];
Expand Down
1 change: 1 addition & 0 deletions Seuss for iPad/SSStatement.h
Expand Up @@ -18,6 +18,7 @@
@property (nonatomic, retain) SSCommand *command;
@property (nonatomic, retain) NSSet *parameters;
@property (nonatomic, retain) SSProgram *program;

@end

@interface SSStatement (CoreDataGeneratedAccessors)
Expand Down
8 changes: 5 additions & 3 deletions Seuss for iPad/SSStatementView.h
Expand Up @@ -7,6 +7,7 @@
//

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@class SSStatement;
@class SSCommand;
Expand All @@ -20,10 +21,11 @@

- (void)addParameterGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;

- (void)prepareForParameterView:(UIView *)variableView atPoint:(CGPoint)point;
- (void)prepareForParameterView:(UIView *)variableView atIndex:(NSUInteger)index;
- (void)prepareForParameterView:(UIView *)variableView atPoint:(CGPoint)point animated:(BOOL)animated;
- (void)prepareForParameterView:(UIView *)variableView atIndex:(NSUInteger)index animated:(BOOL)animated;
- (BOOL)addParameterView:(UIView *)variableView atPoint:(CGPoint)point;
- (BOOL)addParameterView:(UIView *)variableView atIndex:(NSUInteger)index;
- (void)unprepare;
- (BOOL)removeParameterForView:(UIView *)variableView;
- (void)unprepareAnimated:(BOOL)animated;

@end

0 comments on commit 9a99195

Please sign in to comment.