Skip to content

Commit

Permalink
Upgrade to Swift4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Sep 23, 2017
1 parent 3e900b2 commit 8d253cc
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 38 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[![Swift Version][swift-image]][swift-url]
[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/TBXark/TKRubberIndicator/master/LICENSE)
[![CocoaPods](http://img.shields.io/cocoapods/v/TKRubberPageControl.svg?style=flat)](http://cocoapods.org/?q= TKRubberPageControl)
[![CocoaPods](http://img.shields.io/cocoapods/p/TKRubberPageControl.svg?style=flat)](http://cocoapods.org/?q= TKRubberPageControl)
[![CocoaPods](http://img.shields.io/cocoapods/v/TKRubberPageControl.svg?style=flat)](http://cocoapods.org/?q=TKRubberPageControl)
[![CocoaPods](http://img.shields.io/cocoapods/p/TKRubberPageControl.svg?style=flat)](http://cocoapods.org/?q=TKRubberPageControl)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Support](https://img.shields.io/badge/support-iOS%208%2B%20-blue.svg?style=flat)](https://www.apple.com/nl/ios/)

Expand All @@ -13,9 +13,9 @@

## Requirements

- Swift 3.0
- Swift 4.0
- iOS 8.0+
- Xcode 8.0
- Xcode 9.0

## Installation

Expand All @@ -38,7 +38,7 @@ import TKRubberPageControl
Create a `Cartfile` that lists the framework and run `carthage update`. Follow the [instructions](https://github.com/Carthage/Carthage#if-youre-building-for-ios) to add `$(SRCROOT)/Carthage/Build/iOS/TKRubberPageControl.framework` to an iOS project.

```
github "tbxark/TKRubberPageControl"
github "tbxark/TKRubberIndicator"
```
#### Manually
1. Download and drop ```TKRubberPageControl.swift``` in your project.
Expand Down Expand Up @@ -98,6 +98,9 @@ class ViewController: UIViewController {

## Release History

* 1.4.0
Swift 4.0

* 1.3.1
Bug Fixed

Expand Down
16 changes: 10 additions & 6 deletions TKRubberIndicator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@
6A555EC51BDE277B00FC36E6 = {
CreatedOnToolsVersion = 7.1;
DevelopmentTeam = 858CBVXSWP;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
};
6A9103F51D539B370009451B = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 858CBVXSWP;
LastSwiftMigration = 0820;
LastSwiftMigration = 0900;
};
};
};
Expand Down Expand Up @@ -372,7 +372,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.TBXark.TKRubberIndicator;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -386,7 +387,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.TBXark.TKRubberIndicator;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -409,7 +411,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -434,7 +437,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.TBXark.TKRubberPageControl;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -45,6 +46,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion TKRubberIndicator/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ViewController: UIViewController {
@IBAction func pageCountChange(_ sender: UISegmentedControl) {
page.numberOfpage = sender.selectedSegmentIndex + 3
}
func targetActionValueChange(_ page:TKRubberPageControl){
@objc func targetActionValueChange(_ page:TKRubberPageControl){
print("Target-Action : Page is \(page.currentIndex)")
}

Expand Down
52 changes: 26 additions & 26 deletions TKRubberPageControl/TKRubberPageControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import UIKit
private enum TKMoveDirection{
case left
case right
func toBool() -> Bool{
func toLeft() -> Bool{
switch self{
case .left:
return true
Expand Down Expand Up @@ -88,21 +88,21 @@ open class TKRubberPageControl : UIControl {
}

// 手势
fileprivate var indexTap : UITapGestureRecognizer?
private var indexTap : UITapGestureRecognizer?
// 所有图层
fileprivate var smallBubbles = [TKBubbleCell]()
fileprivate var backgroundLayer = CAShapeLayer()
fileprivate var mainBubble = CAShapeLayer()
fileprivate var backLineLayer = CAShapeLayer()
private var smallBubbles = [TKBubbleCell]()
private var backgroundLayer = CAShapeLayer()
private var mainBubble = CAShapeLayer()
private var backLineLayer = CAShapeLayer()

// 大球缩放比例
fileprivate let bubbleScale : CGFloat = 1/3.0
private let bubbleScale : CGFloat = 1/3.0

// 存储计算用的
fileprivate var xPointbegin : CGFloat = 0
fileprivate var xPointEnd : CGFloat = 0
fileprivate var yPointbegin : CGFloat = 0
fileprivate var yPointEnd : CGFloat = 0
private var xPointbegin : CGFloat = 0
private var xPointEnd : CGFloat = 0
private var yPointbegin : CGFloat = 0
private var yPointEnd : CGFloat = 0


public init(frame: CGRect, count: Int, config: TKRubberPageControlConfig = TKRubberPageControlConfig()) {
Expand All @@ -118,7 +118,7 @@ open class TKRubberPageControl : UIControl {
setUpView()
}

fileprivate func setUpView(){
private func setUpView(){

// 一些奇怪的位置计算

Expand Down Expand Up @@ -202,7 +202,7 @@ open class TKRubberPageControl : UIControl {


// 手势事件
@objc fileprivate func tapValueChange(_ ges: UITapGestureRecognizer){
@objc private func tapValueChange(_ ges: UITapGestureRecognizer){
let point = ges.location(in: self)
if point.y > yPointbegin && point.y < yPointEnd && point.x > xPointbegin && point.x < xPointEnd{
let index = Int(point.x - xPointbegin) / Int(styleConfig.smallBubbleMoveRadius)
Expand All @@ -211,7 +211,7 @@ open class TKRubberPageControl : UIControl {
}

// Index值变化
fileprivate func changIndexToValue(_ valueIndex: Int){
private func changIndexToValue(_ valueIndex: Int){
var index = valueIndex
if index >= numberOfpage { index = numberOfpage - 1 }
if index < 0 { index = 0 }
Expand All @@ -222,7 +222,7 @@ open class TKRubberPageControl : UIControl {

// 小球动画
for index in range{
let smallBubbleIndex = (direction.toBool()) ? (index - 1) : (index)
let smallBubbleIndex = (direction.toLeft()) ? (index - 1) : (index)
let smallBubble = smallBubbles[smallBubbleIndex]
smallBubble.positionChange(direction,
radius: styleConfig.smallBubbleMoveRadius / 2,
Expand Down Expand Up @@ -268,11 +268,11 @@ open class TKRubberPageControl : UIControl {
// MARK: - Small Bubble
private class TKBubbleCell: CAShapeLayer, CAAnimationDelegate {

fileprivate var bubbleLayer = CAShapeLayer()
fileprivate let bubbleScale : CGFloat = 0.5
fileprivate var lastDirection : TKMoveDirection!
fileprivate var styleConfig : TKRubberPageControlConfig
fileprivate var cachePosition = CGPoint.zero
var bubbleLayer = CAShapeLayer()
let bubbleScale : CGFloat = 0.5
var lastDirection : TKMoveDirection!
var styleConfig : TKRubberPageControlConfig
var cachePosition = CGPoint.zero

override init(layer: Any) {
styleConfig = TKRubberPageControlConfig()
Expand All @@ -293,7 +293,7 @@ private class TKBubbleCell: CAShapeLayer, CAAnimationDelegate {
setupLayer()
}

fileprivate func setupLayer(){
private func setupLayer(){
frame = CGRect(x: 0, y: 0, width: styleConfig.smallBubbleSize, height: styleConfig.smallBubbleSize)

bubbleLayer.path = UIBezierPath(ovalIn: bounds).cgPath
Expand All @@ -305,13 +305,13 @@ private class TKBubbleCell: CAShapeLayer, CAAnimationDelegate {
}

// beginTime 本来是留给小球轮播用的, 但是效果不好就没用了
internal func positionChange(_ direction: TKMoveDirection, radius: CGFloat, duration: CFTimeInterval, beginTime: CFTimeInterval){
func positionChange(_ direction: TKMoveDirection, radius: CGFloat, duration: CFTimeInterval, beginTime: CFTimeInterval){

let toLeft = direction.toBool()
let toLeft = direction.toLeft()
let movePath = UIBezierPath()
var center = CGPoint.zero
let startAngle = toLeft ? 0 : CGFloat(M_PI)
let endAngle = toLeft ? CGFloat(M_PI) : 0
let startAngle = toLeft ? 0 : CGFloat.pi
let endAngle = toLeft ? CGFloat.pi : 0
center.x += radius * (toLeft ? -1 : 1)
lastDirection = direction

Expand Down Expand Up @@ -368,7 +368,7 @@ private class TKBubbleCell: CAShapeLayer, CAAnimationDelegate {
CATransaction.setAnimationDuration(0)
CATransaction.setDisableActions(true)
var point = cachePosition
point.x += (styleConfig.smallBubbleSize + styleConfig.bubbleXOffsetSpace) * CGFloat(lastDirection.toBool() ? -1 : 1)
point.x += (styleConfig.smallBubbleSize + styleConfig.bubbleXOffsetSpace) * CGFloat(lastDirection.toLeft() ? -1 : 1)
position = point
opacity = 1
CATransaction.commit()
Expand Down

0 comments on commit 8d253cc

Please sign in to comment.