Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c78c75046 | |||
| 6d2380f065 | |||
| 2c039420a0 | |||
| 9f42265ce4 | |||
| 75f7b8b8a6 | |||
| 1aca7f9b00 | |||
| 27189bd7e2 | |||
| 269a4a0036 | |||
| 779c80b2f5 | |||
| 9bd7a42e2f | |||
| db7ba38c71 | |||
| 937322b2b6 |
@@ -45,7 +45,11 @@ open class RAMPaperSwitch: UISwitch, CAAnimationDelegate {
|
||||
fileprivate var oldState = false
|
||||
|
||||
fileprivate var defaultTintColor: UIColor?
|
||||
fileprivate(set) var parentView: UIView?
|
||||
@IBOutlet open var parentView: UIView? {
|
||||
didSet {
|
||||
defaultTintColor = parentView?.backgroundColor
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Initialization
|
||||
|
||||
@@ -68,18 +72,17 @@ open class RAMPaperSwitch: UISwitch, CAAnimationDelegate {
|
||||
}
|
||||
|
||||
override open func awakeFromNib() {
|
||||
self.commonInit(superview)
|
||||
self.commonInit(parentView ?? superview)
|
||||
super.awakeFromNib()
|
||||
}
|
||||
|
||||
// MARK: Helpers
|
||||
|
||||
fileprivate func commonInit(_ parentView: UIView?) {
|
||||
guard let onTintColor = self.onTintColor else {
|
||||
fatalError("set tint color")
|
||||
}
|
||||
self.parentView = parentView
|
||||
self.defaultTintColor = parentView?.backgroundColor
|
||||
defaultTintColor = parentView?.backgroundColor
|
||||
|
||||
layer.borderWidth = 0.5
|
||||
layer.borderColor = UIColor.white.cgColor
|
||||
@@ -97,17 +100,21 @@ open class RAMPaperSwitch: UISwitch, CAAnimationDelegate {
|
||||
}
|
||||
|
||||
override open func layoutSubviews() {
|
||||
let x:CGFloat = max(frame.midX, superview!.frame.size.width - frame.midX);
|
||||
let y:CGFloat = max(frame.midY, superview!.frame.size.height - frame.midY);
|
||||
radius = sqrt(x*x + y*y);
|
||||
|
||||
if let parentView = self.parentView {
|
||||
let x:CGFloat = max(center.x, parentView.frame.size.width - frame.midX)
|
||||
let y:CGFloat = max(center.y, parentView.frame.size.height - frame.midY)
|
||||
radius = sqrt(x*x + y*y)
|
||||
}
|
||||
|
||||
let additional = parentView == superview ? CGPoint.zero : (superview?.frame.origin ?? CGPoint.zero)
|
||||
|
||||
shape.frame = CGRect(x: frame.midX - radius, y: frame.midY - radius, width: radius * 2, height: radius * 2)
|
||||
shape.frame = CGRect(x: center.x - radius + additional.x - 2, y: center.y - radius + additional.y, width: radius * 2, height: radius * 2)
|
||||
shape.anchorPoint = CGPoint(x: 0.5, y: 0.5);
|
||||
shape.path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: radius * 2, height: radius * 2)).cgPath
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
open override func setOn(_ on: Bool, animated: Bool) {
|
||||
let changed:Bool = on != self.isOn
|
||||
|
||||
@@ -119,7 +126,6 @@ open class RAMPaperSwitch: UISwitch, CAAnimationDelegate {
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
fileprivate func showShapeIfNeed() {
|
||||
shape.transform = isOn ? CATransform3DMakeScale(1.0, 1.0, 1.0) : CATransform3DMakeScale(0.0001, 0.0001, 0.0001)
|
||||
}
|
||||
@@ -129,7 +135,6 @@ open class RAMPaperSwitch: UISwitch, CAAnimationDelegate {
|
||||
}
|
||||
|
||||
// MARK: - Animations
|
||||
|
||||
fileprivate func animateKeyPath(_ keyPath: String, fromValue from: CGFloat?, toValue to: CGFloat, timing timingFunction: String) -> CABasicAnimation {
|
||||
|
||||
let animation:CABasicAnimation = CABasicAnimation(keyPath: keyPath)
|
||||
@@ -173,7 +178,6 @@ open class RAMPaperSwitch: UISwitch, CAAnimationDelegate {
|
||||
}
|
||||
|
||||
//MARK: - CAAnimation Delegate
|
||||
|
||||
open func animationDidStart(_ anim: CAAnimation) {
|
||||
parentView?.backgroundColor = defaultTintColor
|
||||
animationDidStartClosure(isOn)
|
||||
|
||||
Vendored
BIN
Binary file not shown.
@@ -265,6 +265,7 @@
|
||||
TargetAttributes = {
|
||||
84BE57D11CFF03ED0073C92B = {
|
||||
CreatedOnToolsVersion = 7.3.1;
|
||||
DevelopmentTeam = 34MUF9YXTA;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
9C6889F91A274993008BFF1E = {
|
||||
@@ -373,17 +374,18 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEFINES_MODULE = YES;
|
||||
DEVELOPMENT_TEAM = 34MUF9YXTA;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
INFOPLIST_FILE = PaperSwitch/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.PaperSwitch;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -409,7 +411,7 @@
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
INFOPLIST_FILE = PaperSwitch/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.PaperSwitch;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -458,7 +460,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
@@ -499,7 +501,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
@@ -516,9 +518,9 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
INFOPLIST_FILE = PaperSwitchDemo/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "ramotion.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.dev;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
@@ -531,9 +533,9 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
INFOPLIST_FILE = PaperSwitchDemo/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "ramotion.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.ramotion.dev;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>Launch</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
@@ -42,7 +44,5 @@
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'RAMPaperSwitch'
|
||||
s.version = '1.0.4'
|
||||
s.version = '2.0.3'
|
||||
s.summary = 'Swift subclass of the UISwitch which paints over the parent view'
|
||||
s.homepage = 'https://github.com/Ramotion/paper-switch'
|
||||
s.license = 'MIT'
|
||||
s.author = { 'juri.v' => 'juri.v@ramotion.com' }
|
||||
s.source = { :git => 'https://github.com/Ramotion/paper-switch.git', :tag => s.version.to_s }
|
||||
s.ios.deployment_target = '8.0'
|
||||
s.ios.deployment_target = '9.0'
|
||||
s.source_files = 'PaperSwitch/*.swift'
|
||||
s.requires_arc = true
|
||||
end
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
[](https://github.com/Ramotion/paper-switch)
|
||||
[](http://twitter.com/Ramotion)
|
||||
[](https://travis-ci.org/Ramotion/paper-switch)
|
||||
[](https://github.com/igrigorik/ga-beacon)
|
||||
|
||||
## About
|
||||
This project is maintained by Ramotion, an agency specialized in building dedicated engineering teams and developing custom software.<br><br> [Contact our team](https://business.ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=paper-switch-contact-us) and we’ll help you work with the best engineers from Eastern Europe.
|
||||
|
||||
This project is maintained by Ramotion, Inc.<br>
|
||||
We specialize in the designing and coding of custom UI for Mobile Apps and Websites.<br><br>**Looking for developers for your project?** [[▶︎CONTACT OUR TEAM◀︎](http://business.ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=paper-switch-contact-us/#Get_in_Touch)]
|
||||
|
||||
#Screenshot
|
||||
[](https://dribbble.com/shots/1749645-Contact-Sync)
|
||||
@@ -22,14 +23,13 @@ The [iPhone mockup](https://store.ramotion.com/product/iphone-6-plus-mockups?utm
|
||||
- iOS 8.0+
|
||||
- Xcode 6.1
|
||||
|
||||
|
||||
#Installation
|
||||
|
||||
Just add the `RAMPaperSwitch` folder to your project.
|
||||
|
||||
or use [CocoaPods](https://cocoapods.org) with Podfile:
|
||||
``` ruby
|
||||
pod 'RAMPaperSwitch'
|
||||
pod 'RAMPaperSwitch', '~> 2.0.3'
|
||||
```
|
||||
or [Carthage](https://github.com/Carthage/Carthage) users can simply add to their `Cartfile`:
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user