Permalink
Browse files

First commit

  • Loading branch information...
1 parent 8b2de3c commit c115347b89c457df5f0c66101a95a3b5cc94d14b @wokalski committed Apr 30, 2012
Showing with 2,394 additions and 0 deletions.
  1. BIN .DS_Store
  2. +34 −0 CDCircleGestureRecognizer.h
  3. +172 −0 CDCircleGestureRecognizer.m
  4. +379 −0 Wheel demo.xcodeproj/project.pbxproj
  5. +7 −0 Wheel demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  6. BIN ...eproj/project.xcworkspace/xcuserdata/wojciechczekalski.xcuserdatad/UserInterfaceState.xcuserstate
  7. +10 −0 ...odeproj/project.xcworkspace/xcuserdata/wojciechczekalski.xcuserdatad/WorkspaceSettings.xcsettings
  8. +5 −0 Wheel demo.xcodeproj/xcuserdata/wojciechczekalski.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
  9. +98 −0 Wheel demo.xcodeproj/xcuserdata/wojciechczekalski.xcuserdatad/xcschemes/Wheel.xcscheme
  10. +22 −0 Wheel demo.xcodeproj/xcuserdata/wojciechczekalski.xcuserdatad/xcschemes/xcschememanagement.plist
  11. +48 −0 Wheel demo/CDCircle.h
  12. +134 −0 Wheel demo/CDCircle.m
  13. +22 −0 Wheel demo/CDCircleOverlayView.h
  14. +56 −0 Wheel demo/CDCircleOverlayView.m
  15. +37 −0 Wheel demo/CDCircleThumb.h
  16. +172 −0 Wheel demo/CDCircleThumb.m
  17. +17 −0 Wheel demo/CDIconView.h
  18. +53 −0 Wheel demo/CDIconView.m
  19. +19 −0 Wheel demo/CDWheelAppDelegate.h
  20. +67 −0 Wheel demo/CDWheelAppDelegate.m
  21. +12 −0 Wheel demo/CDWheelViewController.h
  22. +125 −0 Wheel demo/CDWheelViewController.m
  23. +27 −0 Wheel demo/Common.h
  24. +49 −0 Wheel demo/Common.m
  25. +40 −0 Wheel demo/Wheel-Info.plist
  26. +14 −0 Wheel demo/Wheel-Prefix.pch
  27. +119 −0 Wheel demo/en.lproj/CDWheelViewController.xib
  28. +2 −0 Wheel demo/en.lproj/InfoPlist.strings
  29. BIN Wheel demo/iPod Click.aiff
  30. BIN Wheel demo/icon_arrow_up.png
  31. +18 −0 Wheel demo/main.m
  32. +49 −0 Wheel/CDCircle.h
  33. +137 −0 Wheel/CDCircle.m
  34. +24 −0 Wheel/CDCircleOverlayView.h
  35. +59 −0 Wheel/CDCircleOverlayView.m
  36. +38 −0 Wheel/CDCircleThumb.h
  37. +174 −0 Wheel/CDCircleThumb.m
  38. +18 −0 Wheel/CDIconView.h
  39. +55 −0 Wheel/CDIconView.m
  40. +29 −0 Wheel/Common.h
  41. +53 −0 Wheel/Common.m
View
BIN .DS_Store
Binary file not shown.
@@ -0,0 +1,34 @@
+//This gesture recognizer is based on KTOneFingerRotationGestureRecognizer made by Kirby Turner.
+
+ // KTOneFingerRotationGestureRecognizer.h
+ // Created by Kirby Turner on 4/22/11.
+ // Copyright 2011 White Peak Software Inc. All rights reserved.
+ //
+
+/*
+Copyright (C) <2012> <Wojciech Czelalski/CzekalskiDev>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+
+#import <UIKit/UIKit.h>
+
+@class CDCircleThumb;
+@interface CDCircleGestureRecognizer : UIGestureRecognizer
+{
+ NSDate *previousTouchDate;
+ double currentTransformAngle;
+}
+
+
+@property (nonatomic, assign) BOOL ended;
+@property (nonatomic, assign) CGFloat rotation;
+@property (nonatomic, assign) CGPoint controlPoint;
+@property (nonatomic, strong) CDCircleThumb *currentThumb;
+@end
View
@@ -0,0 +1,172 @@
+/*
+ Copyright (C) <2012> <Wojciech Czelalski/CzekalskiDev>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#define deceleration_multiplier 30.0f
+
+#import <QuartzCore/QuartzCore.h>
+#import "CDCircleGestureRecognizer.h"
+#import <UIKit/UIGestureRecognizerSubclass.h>
+#import "CDCircle.h"
+#import "CDCircleThumb.h"
+#import <AudioToolbox/AudioServices.h>
+#import "CDCircleOverlayView.h"
+#import "Common.h"
+
+
+@implementation CDCircleGestureRecognizer
+
+@synthesize rotation = rotation_, controlPoint;
+@synthesize ended;
+@synthesize currentThumb;
+- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ CDCircle *view = (CDCircle *) [self view];
+ UITouch *touch = [touches anyObject];
+ CGPoint point = [touch locationInView:view];
+
+ // Fail when more than 1 finger detected.
+ if ([[event touchesForGestureRecognizer:self] count] > 1 || ([view.path containsPoint:point] == YES )) {
+ [self setState:UIGestureRecognizerStateFailed];
+ }
+ self.ended = NO;
+
+}
+
+- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ if ([self state] == UIGestureRecognizerStatePossible) {
+ [self setState:UIGestureRecognizerStateBegan];
+ } else {
+ [self setState:UIGestureRecognizerStateChanged];
+ }
+
+ // We can look at any touch object since we know we
+ // have only 1. If there were more than 1 then
+ // touchesBegan:withEvent: would have failed the recognizer.
+ UITouch *touch = [touches anyObject];
+
+ // To rotate with one finger, we simulate a second finger.
+ // The second figure is on the opposite side of the virtual
+ // circle that represents the rotation gesture.
+
+ CDCircle *view = (CDCircle *) [self view];
+ CGPoint center = CGPointMake(CGRectGetMidX([view bounds]), CGRectGetMidY([view bounds]));
+ CGPoint currentTouchPoint = [touch locationInView:view];
+ CGPoint previousTouchPoint = [touch previousLocationInView:view];
+ previousTouchDate = [NSDate date];
+ CGFloat angleInRadians = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
+ [self setRotation:angleInRadians];
+ currentTransformAngle = atan2f(view.transform.b, view.transform.a);
+
+}
+
+- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ // Perform final check to make sure a tap was not misinterpreted.
+ if ([self state] == UIGestureRecognizerStateChanged) {
+
+
+ CDCircle *view = (CDCircle *) [self view];
+ CGFloat flipintime;
+ CGFloat angle = 0;
+ if (view.inertiaeffect == YES) {
+ CGFloat angleInRadians = atan2f(view.transform.b, view.transform.a) - currentTransformAngle;
+ double time = [[NSDate date] timeIntervalSinceDate:previousTouchDate];
+ double velocity = angleInRadians/time;
+ CGFloat a = deceleration_multiplier;
+
+ flipintime = fabs(velocity)/a;
+
+
+
+ angle = (velocity*flipintime)-(a*flipintime*flipintime/2);
+
+ if (angle>M_PI/2 || (angle<0 && angle<-1*M_PI/2)) {
+ if (angle<0) {
+ angle =-1 * M_PI/2.1f;
+ }
+ else { angle = M_PI/2.1f; }
+
+ flipintime = 1/(-1*(a/2*velocity/angle));
+ }
+
+ }
+
+
+
+ [UIView animateWithDuration:flipintime delay:0.f options:UIViewAnimationCurveEaseOut animations:^{
+ [view setTransform:CGAffineTransformRotate(view.transform,angle)];
+
+ } completion:^(BOOL finished) {
+ for (CDCircleThumb *thumb in view.thumbs) {
+
+
+ CGPoint point = [thumb convertPoint:thumb.centerPoint toView:nil];
+ CDCircleThumb *shadow = view.overlayView.overlayThumb;
+ CGRect shadowRect = [shadow.superview convertRect:shadow.frame toView:nil];
+
+ if (CGRectContainsPoint(shadowRect, point) == YES) {
+ CGPoint pointInShadowRect = [thumb convertPoint:thumb.centerPoint toView:shadow];
+ if (CGPathContainsPoint(shadow.arc.CGPath, NULL, pointInShadowRect, NULL)) {
+ CGAffineTransform current = view.transform;
+
+
+ CGFloat deltaAngle= - degreesToRadians(180) + atan2(view.transform.a, view.transform.b) + atan2(thumb.transform.a, thumb.transform.b);
+
+
+ [UIView animateWithDuration:0.2f animations:^{
+ [view setTransform:CGAffineTransformRotate(current, deltaAngle)];
+ }];
+
+
+
+
+
+
+ SystemSoundID soundID;
+ NSString *filePath = [[NSBundle mainBundle] pathForResource:@"iPod Click" ofType:@"aiff"];
+
+ NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
+ AudioServicesCreateSystemSoundID((__bridge CFURLRef)fileUrl, &soundID);
+ AudioServicesPlaySystemSound(soundID);
+
+ [currentThumb.iconView setIsSelected:NO];
+ [thumb.iconView setIsSelected:YES];
+ self.currentThumb = thumb;
+ //Delegate method
+ [view.delegate circle:view didMoveToSegment:thumb.tag thumb:thumb];
+ self.ended = YES;
+ break;
+ }
+
+ }
+ }
+;
+ }];
+
+
+ currentTransformAngle = 0;
+
+
+
+ [self setState:UIGestureRecognizerStateEnded];
+
+ } else {
+ [self setState:UIGestureRecognizerStateFailed];
+ }
+}
+
+
+
+- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [self setState:UIGestureRecognizerStateFailed];
+}
+@end
Oops, something went wrong.

0 comments on commit c115347

Please sign in to comment.