diff --git a/PDKTSwipableCard.xcodeproj/project.pbxproj b/PDKTSwipableCard.xcodeproj/project.pbxproj index bd75e65..1146e11 100644 --- a/PDKTSwipableCard.xcodeproj/project.pbxproj +++ b/PDKTSwipableCard.xcodeproj/project.pbxproj @@ -100,6 +100,7 @@ TargetAttributes = { C70B343F1B6D204900D9D56C = { CreatedOnToolsVersion = 7.0; + DevelopmentTeam = FT6Z43AJD2; }; }; }; @@ -254,11 +255,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = FT6Z43AJD2; INFOPLIST_FILE = PDKTSwipableCard/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.produkt.PDKTSwipableCard; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "PDKTSwipableCard/CardBehaviour-BridgingHeader.h"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -266,11 +269,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = FT6Z43AJD2; INFOPLIST_FILE = PDKTSwipableCard/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.produkt.PDKTSwipableCard; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "PDKTSwipableCard/CardBehaviour-BridgingHeader.h"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -293,6 +298,7 @@ C70B34541B6D204900D9D56C /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/PDKTSwipableCard.xcodeproj/project.xcworkspace/xcuserdata/robinmalhotra.xcuserdatad/UserInterfaceState.xcuserstate b/PDKTSwipableCard.xcodeproj/project.xcworkspace/xcuserdata/robinmalhotra.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..3389ff3 Binary files /dev/null and b/PDKTSwipableCard.xcodeproj/project.xcworkspace/xcuserdata/robinmalhotra.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/PDKTSwipableCard.xcodeproj/xcuserdata/robinmalhotra.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/PDKTSwipableCard.xcodeproj/xcuserdata/robinmalhotra.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..a2a69ac --- /dev/null +++ b/PDKTSwipableCard.xcodeproj/xcuserdata/robinmalhotra.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/PDKTSwipableCard.xcodeproj/xcuserdata/robinmalhotra.xcuserdatad/xcschemes/xcschememanagement.plist b/PDKTSwipableCard.xcodeproj/xcuserdata/robinmalhotra.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..cc83561 --- /dev/null +++ b/PDKTSwipableCard.xcodeproj/xcuserdata/robinmalhotra.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + PDKTSwipableCard.xcscheme + + orderHint + 0 + + + + diff --git a/PDKTSwipableCard/AppDelegate.swift b/PDKTSwipableCard/AppDelegate.swift index 25f6c83..b30f19a 100644 --- a/PDKTSwipableCard/AppDelegate.swift +++ b/PDKTSwipableCard/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/PDKTSwipableCard/CardBehaviour.swift b/PDKTSwipableCard/CardBehaviour.swift index 62896c9..c8b5ae6 100644 --- a/PDKTSwipableCard/CardBehaviour.swift +++ b/PDKTSwipableCard/CardBehaviour.swift @@ -58,14 +58,14 @@ class CardBehaviour : UIDynamicBehavior { } } - override func willMoveToAnimator(dynamicAnimator: UIDynamicAnimator?) { - super.willMoveToAnimator(dynamicAnimator) + override func willMove(to dynamicAnimator: UIDynamicAnimator?) { + super.willMove(to: dynamicAnimator) guard let bounds = dynamicAnimator?.referenceView?.bounds else { return } - updateFieldsInBounds(bounds) + updateFieldsInBounds(bounds: bounds) } func updateFieldsInBounds(bounds: CGRect) { - if bounds != CGRect.zeroRect { + if bounds != CGRect.zero { let itemBounds = item.bounds let height = bounds.height let width = bounds.width @@ -87,14 +87,14 @@ class CardBehaviour : UIDynamicBehavior { let rightCenter = CGPoint(x: midCenter.x + sideFieldWidth/2 + midSectionWidth/2, y: height/2) print("Left, mid, right: \(leftCenter, midCenter, rightCenter)") - updateRegionForField(fieldBehaviors[VerticalSection.LeftSection.rawValue], leftCenter) - updateRegionForField(fieldBehaviors[VerticalSection.MidSection.rawValue], midCenter) - updateRegionForField(fieldBehaviors[VerticalSection.RightSection.rawValue], rightCenter) + updateRegionForField(field: fieldBehaviors[VerticalSection.LeftSection.rawValue], leftCenter) + updateRegionForField(field: fieldBehaviors[VerticalSection.MidSection.rawValue], midCenter) + updateRegionForField(field: fieldBehaviors[VerticalSection.RightSection.rawValue], rightCenter) } } func addLinearVelocity(velocity: CGPoint) { - itemBehavior.addLinearVelocity(velocity, forItem: item) + itemBehavior.addLinearVelocity(velocity, for: item) } func positionForSection(section: VerticalSection) -> CGPoint { @@ -105,7 +105,7 @@ class CardBehaviour : UIDynamicBehavior { if let bounds = dynamicAnimator?.referenceView?.bounds { let position = item.center let thirdWidth = bounds.width / 3.0 - var rect = CGRect(origin: CGPoint.zeroPoint, size: CGSize(width: thirdWidth, height: bounds.height)) + var rect = CGRect(origin: CGPoint.zero, size: CGSize(width: thirdWidth, height: bounds.height)) if rect.contains(position) { return .LeftSection } @@ -119,4 +119,4 @@ class CardBehaviour : UIDynamicBehavior { return nil } -} \ No newline at end of file +} diff --git a/PDKTSwipableCard/ViewController.swift b/PDKTSwipableCard/ViewController.swift index ae59045..25d87ea 100644 --- a/PDKTSwipableCard/ViewController.swift +++ b/PDKTSwipableCard/ViewController.swift @@ -16,7 +16,7 @@ class ViewController: UIViewController { let midSectionWidth : CGFloat = 360 let itemAspectRatio: CGFloat = 0.9 - var offset = CGPoint.zeroPoint + var offset = CGPoint.zero override func viewDidLoad() { super.viewDidLoad() @@ -26,20 +26,20 @@ class ViewController: UIViewController { } func setupSquareView() { - let screenBounds = UIScreen.mainScreen().bounds + let screenBounds = UIScreen.main.bounds let length = floor(0.3 * max(screenBounds.width, screenBounds.height)) itemView = UIView(frame: CGRect(x: screenBounds.width/2 - 100, y: screenBounds.height/2, width: length, height: floor(length / itemAspectRatio))) itemView.autoresizingMask = [] itemView.layer.cornerRadius = 10 - itemView.backgroundColor = UIColor.blueColor() + itemView.backgroundColor = UIColor.blue } func addGestureRecognizers() { - let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "pan:") + let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(pan(pan:))) itemView.addGestureRecognizer(panGestureRecognizer) view.addSubview(itemView) - let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "longPress:") + let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPress(longPress:))) view.addGestureRecognizer(longPressGestureRecognizer) } @@ -51,47 +51,47 @@ class ViewController: UIViewController { } func pan(pan: UIPanGestureRecognizer) { - var location = pan.locationInView(view) - let xDistance = itemView.center.x - CGRectGetWidth(view.frame)/2 + var location = pan.location(in: view) + let xDistance = itemView.center.x - (view.frame.width)/2 switch pan.state { - case .Began: + case .began: let center = itemView.center offset.x = location.x - center.x offset.y = location.y - center.y cardBehavior.isEnabled = false - UIView.animateWithDuration(1.0, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: UIViewAnimationOptions.AllowUserInteraction, animations: { () -> Void in - self.itemView.transform = CGAffineTransformScale(self.itemView.transform, 1.2, 1.2) + UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: UIViewAnimationOptions.allowUserInteraction, animations: { () -> Void in + self.itemView.transform = CGAffineTransform.init(scaleX: 1.2, y: 1.2) }, completion: nil) - case .Changed: + case .changed: location.x -= offset.x location.y -= offset.y itemView.center = location - itemView.transform = CGAffineTransformMakeRotation(xDistance/500) - itemView.backgroundColor = colorForXPosition(xDistance) + itemView.transform = CGAffineTransform.init(rotationAngle: xDistance/500) + itemView.backgroundColor = colorForXPosition(xPosition: xDistance) - case .Cancelled, .Ended: - UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: UIViewAnimationOptions.AllowUserInteraction, animations: { () -> Void in - self.itemView.transform = CGAffineTransformIdentity + case .cancelled, .ended: + UIView.animate(withDuration: 0.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: UIViewAnimationOptions.allowUserInteraction, animations: { () -> Void in + self.itemView.transform = CGAffineTransform.identity }, completion: nil) - let velocity = pan.velocityInView(view) + let velocity = pan.velocity(in: view) cardBehavior.isEnabled = true - cardBehavior.addLinearVelocity(velocity) + cardBehavior.addLinearVelocity(velocity: velocity) default: () } } func longPress(longPress: UILongPressGestureRecognizer) { - guard longPress.state == .Began else { return } - animator.debugEnabled = !animator.debugEnabled + guard longPress.state == .began else { return } + animator.isDebugEnabled = !animator.isDebugEnabled } func colorForXPosition(xPosition : CGFloat) -> UIColor { - let bluecolor = UIColor.blueColor() - let finalColor = xPosition > 0 ? UIColor.greenColor() : UIColor.redColor() + let bluecolor = UIColor.blue + let finalColor = xPosition > 0 ? UIColor.green : UIColor.red if xPosition < -midSectionWidth/2 { return finalColor } else if xPosition > midSectionWidth/2 { @@ -102,10 +102,10 @@ class ViewController: UIViewController { } extension ViewController : UIDynamicAnimatorDelegate { - func dynamicAnimatorDidPause(animator: UIDynamicAnimator) { + func dynamicAnimatorDidPause(_ animator: UIDynamicAnimator) { if itemView.center != view.center { itemView.center = view.center - itemView.backgroundColor = UIColor.blueColor() + itemView.backgroundColor = UIColor.blue } } }