Skip to content

Commit 8d253cc

Browse files
committed
Upgrade to Swift4.0
1 parent 3e900b2 commit 8d253cc

File tree

6 files changed

+47
-38
lines changed

6 files changed

+47
-38
lines changed

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
44
[![Swift Version][swift-image]][swift-url]
55
[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/TBXark/TKRubberIndicator/master/LICENSE)
6-
[![CocoaPods](http://img.shields.io/cocoapods/v/TKRubberPageControl.svg?style=flat)](http://cocoapods.org/?q= TKRubberPageControl)
7-
[![CocoaPods](http://img.shields.io/cocoapods/p/TKRubberPageControl.svg?style=flat)](http://cocoapods.org/?q= TKRubberPageControl)
6+
[![CocoaPods](http://img.shields.io/cocoapods/v/TKRubberPageControl.svg?style=flat)](http://cocoapods.org/?q=TKRubberPageControl)
7+
[![CocoaPods](http://img.shields.io/cocoapods/p/TKRubberPageControl.svg?style=flat)](http://cocoapods.org/?q=TKRubberPageControl)
88
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
99
[![Support](https://img.shields.io/badge/support-iOS%208%2B%20-blue.svg?style=flat)](https://www.apple.com/nl/ios/)
1010

@@ -13,9 +13,9 @@
1313

1414
## Requirements
1515

16-
- Swift 3.0
16+
- Swift 4.0
1717
- iOS 8.0+
18-
- Xcode 8.0
18+
- Xcode 9.0
1919

2020
## Installation
2121

@@ -38,7 +38,7 @@ import TKRubberPageControl
3838
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.
3939

4040
```
41-
github "tbxark/TKRubberPageControl"
41+
github "tbxark/TKRubberIndicator"
4242
```
4343
#### Manually
4444
1. Download and drop ```TKRubberPageControl.swift``` in your project.
@@ -98,6 +98,9 @@ class ViewController: UIViewController {
9898

9999
## Release History
100100

101+
* 1.4.0
102+
Swift 4.0
103+
101104
* 1.3.1
102105
Bug Fixed
103106

TKRubberIndicator.xcodeproj/project.pbxproj

+10-6
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@
184184
6A555EC51BDE277B00FC36E6 = {
185185
CreatedOnToolsVersion = 7.1;
186186
DevelopmentTeam = 858CBVXSWP;
187-
LastSwiftMigration = 0800;
187+
LastSwiftMigration = 0900;
188188
};
189189
6A9103F51D539B370009451B = {
190190
CreatedOnToolsVersion = 7.3.1;
191191
DevelopmentTeam = 858CBVXSWP;
192-
LastSwiftMigration = 0820;
192+
LastSwiftMigration = 0900;
193193
};
194194
};
195195
};
@@ -372,7 +372,8 @@
372372
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
373373
PRODUCT_BUNDLE_IDENTIFIER = com.TBXark.TKRubberIndicator;
374374
PRODUCT_NAME = "$(TARGET_NAME)";
375-
SWIFT_VERSION = 3.0;
375+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
376+
SWIFT_VERSION = 4.0;
376377
};
377378
name = Debug;
378379
};
@@ -386,7 +387,8 @@
386387
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
387388
PRODUCT_BUNDLE_IDENTIFIER = com.TBXark.TKRubberIndicator;
388389
PRODUCT_NAME = "$(TARGET_NAME)";
389-
SWIFT_VERSION = 3.0;
390+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
391+
SWIFT_VERSION = 4.0;
390392
};
391393
name = Release;
392394
};
@@ -409,7 +411,8 @@
409411
PRODUCT_NAME = "$(TARGET_NAME)";
410412
SKIP_INSTALL = YES;
411413
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
412-
SWIFT_VERSION = 3.0;
414+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
415+
SWIFT_VERSION = 4.0;
413416
TARGETED_DEVICE_FAMILY = "1,2";
414417
VERSIONING_SYSTEM = "apple-generic";
415418
VERSION_INFO_PREFIX = "";
@@ -434,7 +437,8 @@
434437
PRODUCT_BUNDLE_IDENTIFIER = com.TBXark.TKRubberPageControl;
435438
PRODUCT_NAME = "$(TARGET_NAME)";
436439
SKIP_INSTALL = YES;
437-
SWIFT_VERSION = 3.0;
440+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
441+
SWIFT_VERSION = 4.0;
438442
TARGETED_DEVICE_FAMILY = "1,2";
439443
VERSIONING_SYSTEM = "apple-generic";
440444
VERSION_INFO_PREFIX = "";

TKRubberIndicator.xcodeproj/xcuserdata/Tbxark.xcuserdatad/xcschemes/TKRubberIndicator.xcscheme

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
</Testables>
@@ -45,6 +46,7 @@
4546
buildConfiguration = "Debug"
4647
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4748
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49+
language = ""
4850
launchStyle = "0"
4951
useCustomWorkingDirectory = "NO"
5052
ignoresPersistentStateOnLaunch = "NO"

TKRubberIndicator/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ViewController: UIViewController {
3232
@IBAction func pageCountChange(_ sender: UISegmentedControl) {
3333
page.numberOfpage = sender.selectedSegmentIndex + 3
3434
}
35-
func targetActionValueChange(_ page:TKRubberPageControl){
35+
@objc func targetActionValueChange(_ page:TKRubberPageControl){
3636
print("Target-Action : Page is \(page.currentIndex)")
3737
}
3838

TKRubberPageControl/TKRubberPageControl.swift

+26-26
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import UIKit
1414
private enum TKMoveDirection{
1515
case left
1616
case right
17-
func toBool() -> Bool{
17+
func toLeft() -> Bool{
1818
switch self{
1919
case .left:
2020
return true
@@ -88,21 +88,21 @@ open class TKRubberPageControl : UIControl {
8888
}
8989

9090
// 手势
91-
fileprivate var indexTap : UITapGestureRecognizer?
91+
private var indexTap : UITapGestureRecognizer?
9292
// 所有图层
93-
fileprivate var smallBubbles = [TKBubbleCell]()
94-
fileprivate var backgroundLayer = CAShapeLayer()
95-
fileprivate var mainBubble = CAShapeLayer()
96-
fileprivate var backLineLayer = CAShapeLayer()
93+
private var smallBubbles = [TKBubbleCell]()
94+
private var backgroundLayer = CAShapeLayer()
95+
private var mainBubble = CAShapeLayer()
96+
private var backLineLayer = CAShapeLayer()
9797

9898
// 大球缩放比例
99-
fileprivate let bubbleScale : CGFloat = 1/3.0
99+
private let bubbleScale : CGFloat = 1/3.0
100100

101101
// 存储计算用的
102-
fileprivate var xPointbegin : CGFloat = 0
103-
fileprivate var xPointEnd : CGFloat = 0
104-
fileprivate var yPointbegin : CGFloat = 0
105-
fileprivate var yPointEnd : CGFloat = 0
102+
private var xPointbegin : CGFloat = 0
103+
private var xPointEnd : CGFloat = 0
104+
private var yPointbegin : CGFloat = 0
105+
private var yPointEnd : CGFloat = 0
106106

107107

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

121-
fileprivate func setUpView(){
121+
private func setUpView(){
122122

123123
// 一些奇怪的位置计算
124124

@@ -202,7 +202,7 @@ open class TKRubberPageControl : UIControl {
202202

203203

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

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

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

271-
fileprivate var bubbleLayer = CAShapeLayer()
272-
fileprivate let bubbleScale : CGFloat = 0.5
273-
fileprivate var lastDirection : TKMoveDirection!
274-
fileprivate var styleConfig : TKRubberPageControlConfig
275-
fileprivate var cachePosition = CGPoint.zero
271+
var bubbleLayer = CAShapeLayer()
272+
let bubbleScale : CGFloat = 0.5
273+
var lastDirection : TKMoveDirection!
274+
var styleConfig : TKRubberPageControlConfig
275+
var cachePosition = CGPoint.zero
276276

277277
override init(layer: Any) {
278278
styleConfig = TKRubberPageControlConfig()
@@ -293,7 +293,7 @@ private class TKBubbleCell: CAShapeLayer, CAAnimationDelegate {
293293
setupLayer()
294294
}
295295

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

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

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

310-
let toLeft = direction.toBool()
310+
let toLeft = direction.toLeft()
311311
let movePath = UIBezierPath()
312312
var center = CGPoint.zero
313-
let startAngle = toLeft ? 0 : CGFloat(M_PI)
314-
let endAngle = toLeft ? CGFloat(M_PI) : 0
313+
let startAngle = toLeft ? 0 : CGFloat.pi
314+
let endAngle = toLeft ? CGFloat.pi : 0
315315
center.x += radius * (toLeft ? -1 : 1)
316316
lastDirection = direction
317317

@@ -368,7 +368,7 @@ private class TKBubbleCell: CAShapeLayer, CAAnimationDelegate {
368368
CATransaction.setAnimationDuration(0)
369369
CATransaction.setDisableActions(true)
370370
var point = cachePosition
371-
point.x += (styleConfig.smallBubbleSize + styleConfig.bubbleXOffsetSpace) * CGFloat(lastDirection.toBool() ? -1 : 1)
371+
point.x += (styleConfig.smallBubbleSize + styleConfig.bubbleXOffsetSpace) * CGFloat(lastDirection.toLeft() ? -1 : 1)
372372
position = point
373373
opacity = 1
374374
CATransaction.commit()

0 commit comments

Comments
 (0)