Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions GBPageControl.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,15 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Jason Hurt";
TargetAttributes = {
00C05C551C1C839300D4B456 = {
CreatedOnToolsVersion = 7.1;
};
00C05C661C1C854900D4B456 = {
CreatedOnToolsVersion = 7.1;
ProvisioningStyle = Automatic;
};
};
};
Expand Down Expand Up @@ -284,13 +285,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
Expand Down Expand Up @@ -319,6 +328,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -333,13 +343,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
Expand All @@ -359,6 +377,8 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -371,7 +391,7 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -384,6 +404,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -404,40 +425,49 @@
PRODUCT_BUNDLE_IDENTIFIER = com.pulsefix.GBPageControl;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
};
name = Release;
};
00C05C7B1C1C854900D4B456 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = GBPageControlExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.pulsefix.GBPageControlExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
00C05C7C1C1C854900D4B456 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = GBPageControlExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.pulsefix.GBPageControlExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
45 changes: 23 additions & 22 deletions GBPageControl/PageControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ public class PageControl: NSObject {
}

public func handleTouch(touch:UITouch) -> Bool {
let location = touch.locationInNode(pageIndicatorNode!)
let location = touch.location(in: pageIndicatorNode!)
let touchMargin:CGFloat = xMargin / 2.0
for i in 0...pageIndicators!.count - 1 {
let indicator = pageIndicators![i]
if CGRectContainsPoint(CGRect(
if CGRect(
x:indicator.frame.origin.x - touchMargin,
y:indicator.frame.origin.y - touchMargin,
width:indicator.frame.width + touchMargin * 2.0,
height:indicator.frame.height + touchMargin * 2.0), location) {
let point = CGPoint(x:-1.0 * CGFloat(i) * parentScene!.size.width, y:contentNode!.position.y)
contentNode!.runAction(SKAction.moveTo(point, duration:0.2), completion: { [weak self] in
self?.pageStateDidChange()
})
return true
height:indicator.frame.height + touchMargin * 2.0).contains(location) {
let point = CGPoint(x:-1.0 * CGFloat(i) * parentScene!.size.width, y:contentNode!.position.y)
contentNode!.run(SKAction.move(to: point, duration:0.2), completion: { [weak self] in
self?.pageStateDidChange()
})
return true
}
}
return false
Expand All @@ -87,40 +87,40 @@ public class PageControl: NSObject {
pageIndicatorNode.addChild(pageCircle)
pageIndicators.append(pageCircle)
}
pageIndicatorNode.position = CGPoint(x:CGRectGetMidX(parentScene!.frame) - pageIndicatorWidth/2.0, y:yPosition + pageIndicatorHeight/2.0)
pageIndicatorNode.position = CGPoint(x: (parentScene!.frame.size.width / 2) - pageIndicatorWidth/2.0, y:yPosition + pageIndicatorHeight/2.0)
parentScene?.addChild(pageIndicatorNode)
}

private func addPanGestureRecognizer() {
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(PageControl.handlePanGesture(_:)))
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.handlePanGesture))
parentScene?.view?.addGestureRecognizer(panGestureRecognizer)
}

public func handlePanGesture(recognizer: UIPanGestureRecognizer) {
if recognizer.state == UIGestureRecognizerState.Began {
panGestureStartPoint = parentScene?.convertPointFromView(recognizer.locationInView(recognizer.view))
@objc public func handlePanGesture(recognizer: UIPanGestureRecognizer) {
if recognizer.state == UIGestureRecognizerState.began {
panGestureStartPoint = parentScene?.convertPoint(fromView: recognizer.location(in: recognizer.view))
panGestureStartContentPosition = contentNode.position
}
else if recognizer.state == UIGestureRecognizerState.Changed {
else if recognizer.state == UIGestureRecognizerState.changed {
if panGestureStartPoint != nil {
let touchPoint = parentScene?.convertPointFromView(recognizer.locationInView(recognizer.view))
let velocity = recognizer.velocityInView(recognizer.view!)
let slideMultiplier = abs(velocity.x) / 35000
let newPosition = boundContentNode(CGPoint(x: contentNode.position.x - (panGestureStartPoint.x - touchPoint!.x) + (velocity.x * slideMultiplier),
y: contentNode!.position.y))
let touchPoint = parentScene?.convertPoint(fromView: recognizer.location(in: recognizer.view))
let velocity = recognizer.velocity(in: recognizer.view!)
let slideMultiplier : CGFloat = 1 / 100000
let newPosition = boundContentNode(point: CGPoint(x: contentNode.position.x - (panGestureStartPoint.x - touchPoint!.x) + (velocity.x * slideMultiplier),
y: contentNode!.position.y))
if abs(newPosition.x - panGestureStartContentPosition.x) < parentScene!.size.width * 1.4 {
contentNode!.position = newPosition
}
panGestureStartPoint = touchPoint
}
}
else if recognizer.state == UIGestureRecognizerState.Ended {
else if recognizer.state == UIGestureRecognizerState.ended {
panGestureStartPoint = nil
panGestureStartContentPosition = nil
let page = getSelectedPage()
let point = CGPoint(x:-1.0 * CGFloat(page) * parentScene!.size.width, y:contentNode!.position.y)
let moveTo = SKAction.moveTo(point, duration:0.2)
contentNode!.runAction(moveTo)
let moveTo = SKAction.move(to: point, duration:0.2)
contentNode!.run(moveTo)
pageStateDidChange()
}
}
Expand Down Expand Up @@ -150,3 +150,4 @@ public class PageControl: NSObject {
return point
}
}

33 changes: 15 additions & 18 deletions GBPageControlExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,34 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
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:.
}


}

Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -29,6 +39,11 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
16 changes: 8 additions & 8 deletions GBPageControlExample/GameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ import GBPageControl
var pageControl:PageControl!

class GameScene: SKScene {
override func didMoveToView(view: SKView) {
override func didMove(to view: SKView) {
addBackground()
pageControl = PageControl(scene: self)
addContent()
pageControl.enable(4)
pageControl.enable(numberOfPages: 4)
}

override func willMoveFromView(view: SKView) {
pageControl.willMoveFromView(view)
override func willMove(from view: SKView) {
pageControl.willMoveFromView(view: view)
}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
if pageControl.handleTouch(touch) {
if pageControl.handleTouch(touch: touch) {
//no op
}
else {
Expand All @@ -36,7 +36,7 @@ class GameScene: SKScene {

func addBackground() {
let background = SKShapeNode(rect: CGRect(x: 0.0, y: 0.0, width: self.size.width, height: self.size.height))
background.fillColor = UIColor.whiteColor()
background.fillColor = UIColor.white
background.strokeColor = background.fillColor
self.addChild(background)
}
Expand All @@ -47,7 +47,7 @@ class GameScene: SKScene {
let x = self.size.width / 2.0 + self.size.width * CGFloat(i)
let y = self.size.height / 2.0
sprite.position = CGPoint(x:x, y:y)
pageControl.addChild(sprite)
pageControl.addChild(node: sprite)
}
}
}
8 changes: 4 additions & 4 deletions GBPageControlExample/GameViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import UIKit
import SpriteKit

class GameViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
}

override func viewDidAppear(animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let scene = GameScene(size: view.bounds.size)
let skView = view as! SKView
skView.ignoresSiblingOrder = true
scene.scaleMode = .ResizeFill
scene.scaleMode = .resizeFill
skView.presentScene(scene)
}

override func prefersStatusBarHidden() -> Bool {
func prefersStatusBarHidden() -> Bool {
return true
}
}
Loading