Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring ViewController and Spring class #346

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## Updated for Swift 4.2
Requires Xcode 10 and Swift 4.2.
## Updated for Swift 5
Requires Xcode 13 and Swift 5.5

## Installation
Drop in the Spring folder to your Xcode project (make sure to enable "Copy items if needed" and "Create groups").

Or via CocoaPods:
```
use_frameworks!
pod 'Spring', :git => 'https://github.com/MengTo/Spring.git'
pod 'Spring', :git => 'https://github.com/LexDeBash/Spring.git'
```

## Usage with Storyboard
Expand Down
8 changes: 4 additions & 4 deletions Spring.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = 'Spring'
s.version = '1.0.6'
s.version = '1.0.9'
s.license = 'MIT'
s.summary = 'A library to simplify iOS animations in Swift.'
s.homepage = 'https://github.com/MengTo/Spring'
s.homepage = 'https://github.com/LexDeBash/Spring'
s.authors = { 'Meng To' => '[email protected]' }
s.source = { :git => 'https://github.com/MengTo/Spring.git', :tag => s.version.to_s }
s.source = { :git => 'https://github.com/LexDeBash/Spring.git', :tag => s.version.to_s }
s.requires_arc = true
s.ios.deployment_target = '8.0'
s.ios.deployment_target = '14.0'
s.tvos.deployment_target = '11.0'
s.source_files = 'Spring/*.swift'
s.ios.resources = ['Spring/*.xib', 'SpringApp/*.xcassets']
Expand Down
10 changes: 5 additions & 5 deletions Spring/DesignableTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import UIKit
@IBInspectable var firstSelectedImage: UIImage? {
didSet {
if let image = firstSelectedImage {
var tabBarItems = self.tabBar.items as [UITabBarItem]?
let tabBarItems = self.tabBar.items as [UITabBarItem]?
tabBarItems?[0].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}
Expand All @@ -56,7 +56,7 @@ import UIKit
@IBInspectable var secondSelectedImage: UIImage? {
didSet {
if let image = secondSelectedImage {
var tabBarItems = self.tabBar.items as [UITabBarItem]?
let tabBarItems = self.tabBar.items as [UITabBarItem]?
tabBarItems?[1].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}
Expand All @@ -65,7 +65,7 @@ import UIKit
@IBInspectable var thirdSelectedImage: UIImage? {
didSet {
if let image = thirdSelectedImage {
var tabBarItems = self.tabBar.items as [UITabBarItem]?
let tabBarItems = self.tabBar.items as [UITabBarItem]?
tabBarItems?[2].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}
Expand All @@ -74,7 +74,7 @@ import UIKit
@IBInspectable var fourthSelectedImage: UIImage? {
didSet {
if let image = fourthSelectedImage {
var tabBarItems = self.tabBar.items as [UITabBarItem]?
let tabBarItems = self.tabBar.items as [UITabBarItem]?
tabBarItems?[3].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}
Expand All @@ -83,7 +83,7 @@ import UIKit
@IBInspectable var fifthSelectedImage: UIImage? {
didSet {
if let image = fifthSelectedImage {
var tabBarItems = self.tabBar.items as [UITabBarItem]?
let tabBarItems = self.tabBar.items as [UITabBarItem]?
tabBarItems?[4].selectedImage = image.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
}
}
Expand Down
42 changes: 22 additions & 20 deletions Spring/KeyboardLayoutConstraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,34 @@ import UIKit
@available(tvOS, unavailable)
public class KeyboardLayoutConstraint: NSLayoutConstraint {

private var offset : CGFloat = 0
private var keyboardVisibleHeight : CGFloat = 0
private var offset: CGFloat = 0
private var keyboardVisibleHeight: CGFloat = 0

@available(tvOS, unavailable)
override public func awakeFromNib() {
super.awakeFromNib()

offset = constant

NotificationCenter.default.addObserver(self, selector: #selector(KeyboardLayoutConstraint.keyboardWillShowNotification(_:)), name: UIWindow.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardLayoutConstraint.keyboardWillHideNotification(_:)), name: UIWindow.keyboardWillHideNotification, object: nil)
NotificationCenter.default.addObserver(
self,
selector: #selector(KeyboardLayoutConstraint.keyboardWillShowNotification),
name: UIWindow.keyboardWillShowNotification,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(KeyboardLayoutConstraint.keyboardWillHideNotification),
name: UIWindow.keyboardWillHideNotification,
object: nil
)
}

deinit {
NotificationCenter.default.removeObserver(self)
}

// MARK: Notification

@objc func keyboardWillShowNotification(_ notification: Notification) {
if let userInfo = notification.userInfo {
if let frameValue = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
Expand All @@ -61,24 +70,19 @@ public class KeyboardLayoutConstraint: NSLayoutConstraint {
UIView.animate(
withDuration: TimeInterval(duration.doubleValue),
delay: 0,
options: options,
animations: {
UIApplication.shared.keyWindow?.layoutIfNeeded()
options: options) {
UIApplication.shared.windows.first?.layoutIfNeeded()
return
}, completion: { finished in
})
}
default:

break
}

}

}

@objc func keyboardWillHideNotification(_ notification: NSNotification) {
keyboardVisibleHeight = 0
self.updateConstant()
updateConstant()

if let userInfo = notification.userInfo {

Expand All @@ -90,20 +94,18 @@ public class KeyboardLayoutConstraint: NSLayoutConstraint {
UIView.animate(
withDuration: TimeInterval(duration.doubleValue),
delay: 0,
options: options,
animations: {
UIApplication.shared.keyWindow?.layoutIfNeeded()
options: options) {
UIApplication.shared.windows.first?.layoutIfNeeded()
return
}, completion: { finished in
})
}
default:
break
}
}
}

func updateConstant() {
self.constant = offset + keyboardVisibleHeight
constant = offset + keyboardVisibleHeight
}

}
Expand Down
4 changes: 2 additions & 2 deletions Spring/LoadingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public extension UIView {
static let Tag = 1000
}

public func showLoading() {
func showLoading() {

if self.viewWithTag(LoadingViewConstants.Tag) != nil {
// If loading view is already found in current view hierachy, do nothing
Expand All @@ -68,7 +68,7 @@ public extension UIView {
})
}

public func hideLoading() {
func hideLoading() {

if let loadingXibView = self.viewWithTag(LoadingViewConstants.Tag) {
loadingXibView.alpha = 1
Expand Down
18 changes: 11 additions & 7 deletions Spring/LoadingView.xib
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19162" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="2ih-bH-VRI" customClass="LoadingView" customModule="Spring" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="19J-d9-rcw" customClass="SpringView" customModule="Spring" customModuleProvider="target">
<rect key="frame" x="275" y="275" width="50" height="50"/>
<rect key="frame" x="182" y="423" width="50" height="50"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="loading" translatesAutoresizingMaskIntoConstraints="NO" id="e5h-jP-Opi">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
Expand All @@ -21,7 +24,7 @@
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="centerY" secondItem="e5h-jP-Opi" secondAttribute="centerY" id="094-1B-RGw"/>
<constraint firstAttribute="height" constant="50" id="1hh-Ra-6oa"/>
Expand All @@ -30,14 +33,15 @@
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="centerY" secondItem="19J-d9-rcw" secondAttribute="centerY" id="DlX-dJ-y4A"/>
<constraint firstAttribute="centerX" secondItem="19J-d9-rcw" secondAttribute="centerX" id="iTf-dQ-2Ho"/>
</constraints>
<connections>
<outlet property="indicatorView" destination="19J-d9-rcw" id="WZZ-6H-whz"/>
</connections>
<point key="canvasLocation" x="92" y="18"/>
</view>
</objects>
<resources>
Expand Down
Loading