From c92a5b9b7505e3193eb45656b9f12c5f3d054fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5FFinder=E4=B8=B6Tiwk?= <136652711@qq.com> Date: Mon, 25 Jan 2016 20:50:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0ObjectiveC=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PaperSwitchDemo.xcodeproj/project.pbxproj | 19 ++- .../ObjectiveC/FTPaperSwitch.h | 23 +++ .../ObjectiveC/FTPaperSwitch.m | 139 ++++++++++++++++++ 3 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.h create mode 100644 PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.m diff --git a/PaperSwitchDemo/PaperSwitchDemo.xcodeproj/project.pbxproj b/PaperSwitchDemo/PaperSwitchDemo.xcodeproj/project.pbxproj index f56436e..d8453c5 100644 --- a/PaperSwitchDemo/PaperSwitchDemo.xcodeproj/project.pbxproj +++ b/PaperSwitchDemo/PaperSwitchDemo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 1DC9AE9D1C5651070035F785 /* FTPaperSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = 1DC9AE9C1C5651070035F785 /* FTPaperSwitch.m */; }; 846E0ED31C464B5C0052CDD8 /* Launch.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 846E0ED21C464B5C0052CDD8 /* Launch.storyboard */; }; 9C688A001A274993008BFF1E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C6889FF1A274993008BFF1E /* AppDelegate.swift */; }; 9C688A021A274993008BFF1E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C688A011A274993008BFF1E /* ViewController.swift */; }; @@ -27,6 +28,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 1DC9AE9B1C5651070035F785 /* FTPaperSwitch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FTPaperSwitch.h; sourceTree = ""; }; + 1DC9AE9C1C5651070035F785 /* FTPaperSwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FTPaperSwitch.m; sourceTree = ""; }; 846E0ED21C464B5C0052CDD8 /* Launch.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Launch.storyboard; sourceTree = ""; }; 9C6889FA1A274993008BFF1E /* PaperSwitchDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PaperSwitchDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9C6889FE1A274993008BFF1E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -58,6 +61,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 1DC9AE9A1C5650CA0035F785 /* ObjectiveC */ = { + isa = PBXGroup; + children = ( + 1DC9AE9B1C5651070035F785 /* FTPaperSwitch.h */, + 1DC9AE9C1C5651070035F785 /* FTPaperSwitch.m */, + ); + path = ObjectiveC; + sourceTree = ""; + }; 9C6889F11A274993008BFF1E = { isa = PBXGroup; children = ( @@ -79,6 +91,7 @@ 9C6889FC1A274993008BFF1E /* PaperSwitchDemo */ = { isa = PBXGroup; children = ( + 1DC9AE9A1C5650CA0035F785 /* ObjectiveC */, 9C688A211A274A39008BFF1E /* PaperSwitch */, 9C6889FF1A274993008BFF1E /* AppDelegate.swift */, 9C688A011A274993008BFF1E /* ViewController.swift */, @@ -169,7 +182,7 @@ isa = PBXProject; attributes = { LastSwiftMigration = 0700; - LastSwiftUpdateCheck = 0700; + LastSwiftUpdateCheck = 0720; LastUpgradeCheck = 0700; ORGANIZATIONNAME = Ramotion; TargetAttributes = { @@ -228,6 +241,7 @@ files = ( 9C688A021A274993008BFF1E /* ViewController.swift in Sources */, 9C688A231A274A39008BFF1E /* RAMPaperSwitch.swift in Sources */, + 1DC9AE9D1C5651070035F785 /* FTPaperSwitch.m in Sources */, 9C688A001A274993008BFF1E /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -335,11 +349,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; INFOPLIST_FILE = PaperSwitchDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "ramotion.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; }; @@ -347,6 +363,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; INFOPLIST_FILE = PaperSwitchDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.h b/PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.h new file mode 100644 index 0000000..556f52b --- /dev/null +++ b/PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.h @@ -0,0 +1,23 @@ +// +// FTPaperSwitch.h +// PaperSwitchDemo +// +// Created by _Finder丶Tiwk on 16/1/25. +// Copyright © 2016年 Ramotion. All rights reserved. +// + +#import + +@interface FTPaperSwitch : UISwitch + +/*! 动画时间 默认为0.25秒*/ +@property (nonatomic,assign) CFTimeInterval duration; +/*! 展开画面填充颜色,如果不设置,默认为控制底色 绿色*/ +@property (nonatomic,strong) UIColor *fillColor; + +/*! 动画开始回调,从block中的animation参数 可以取到动画相关信息*/ +@property (nonatomic,copy) void (^animationStartBlock)(CAAnimation *animation); +/*! 动画结束回调,从block中的animation参数 可以取到动画相关信息,complete标识动画是否结束*/ +@property (nonatomic,copy) void (^animationStopBlock)(CAAnimation *animation,BOOL complete); + +@end diff --git a/PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.m b/PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.m new file mode 100644 index 0000000..afe9397 --- /dev/null +++ b/PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.m @@ -0,0 +1,139 @@ +// +// FTPaperSwitch.m +// PaperSwitchDemo +// +// Created by _Finder丶Tiwk on 16/1/25. +// Copyright © 2016年 Ramotion. All rights reserved. +// + +#import "FTPaperSwitch.h" + +static NSString *kShapeLayerName = @"circleShape"; + +@interface FTPaperSwitch () +@property (nonatomic,strong) CAShapeLayer *shapLayer; +@end + +@implementation FTPaperSwitch + +#pragma mark - Accessor +- (CAShapeLayer *)shapLayer{ + if (!_shapLayer) { + _shapLayer = [CAShapeLayer layer]; + _shapLayer.name = kShapeLayerName; + _shapLayer.fillColor = [UIColor greenColor].CGColor; + _shapLayer.masksToBounds = YES; + } + return _shapLayer; +} + +- (CFTimeInterval)duration{ + return _duration > 0 ? :0.25; +} + +- (void)setFillColor:(UIColor *)fillColor{ + _fillColor = fillColor; + self.shapLayer.fillColor = fillColor.CGColor; +} + +#pragma mark - 初始化 +- (instancetype)init{ + self = [super init]; + if (self) { + [self addTarget:self action:@selector(switchChanged) forControlEvents:UIControlEventValueChanged]; + } + return self; +} + +- (void)awakeFromNib{ + [super awakeFromNib]; + [self addTarget:self action:@selector(switchChanged) forControlEvents:UIControlEventValueChanged]; +} + + +#pragma mark - 重写UISwitch设置状态方法 + +- (void)setOn:(BOOL)on animated:(BOOL)animated{ + [super setOn:on animated:animated]; + [self switchChanged]; +} + + +- (void)insertIntoSuperLayer{ + BOOL isAdd = NO; + + for (CAShapeLayer *layer in self.superview.layer.sublayers) { + if ([layer.name isEqualToString:kShapeLayerName]) { + isAdd = YES; + break; + } + } + + if (!isAdd) { + [self.superview.layer insertSublayer:self.shapLayer atIndex:0]; + self.superview.layer.masksToBounds = YES; + } +} + +- (void)layoutSubviews{ + [self insertIntoSuperLayer]; + + CGFloat midX = self.center.x; + CGFloat midY = self.center.y; + + CGFloat x = MAX(midX, self.superview.frame.size.width - midX); + CGFloat y = MAX(midY, self.superview.frame.size.height - midY); + + CGFloat radius = sqrt(pow(x, 2) + pow(y, 2)); + self.shapLayer.frame = (CGRect){{midX-radius,midY-radius},{radius*2,radius*2}}; + self.shapLayer.anchorPoint = (CGPoint){0.5,0.5}; + UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:(CGRect){CGPointZero,{radius*2,radius*2}}]; + self.shapLayer.path = bezierPath.CGPath; +} + +- (void)switchChanged{ + + BOOL status = self.on; + CGFloat orgin = 0.0001; + CGFloat final = 1.0; + + NSValue *value1 = [NSValue valueWithCATransform3D:CATransform3DMakeScale(orgin,orgin,orgin)]; + NSValue *value2 = [NSValue valueWithCATransform3D:CATransform3DMakeScale(final,final,final)]; + NSValue *from = status?value1:value2; + NSValue *to = status?value2:value1; + + NSString *animationKey1 = @"ZoomIn"; + NSString *animationKey2 = @"ZoomOut"; + NSString *removeKey = status?animationKey2:animationKey1; + NSString *addKey = status?animationKey1:animationKey2; + NSString *timingFunction = status?kCAMediaTimingFunctionEaseIn:kCAMediaTimingFunctionEaseOut; + + [CATransaction begin]; + [self.shapLayer removeAnimationForKey:removeKey]; + CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"]; + animation.fromValue = from; + animation.toValue = to; + animation.timingFunction = [CAMediaTimingFunction functionWithName:timingFunction]; + animation.removedOnCompletion = NO; + animation.fillMode = kCAFillModeForwards; + animation.duration = self.duration; + animation.delegate = self; + [self.shapLayer addAnimation:animation forKey:addKey]; + [CATransaction commit]; +} + +#pragma mark - CAAnimationDelegate +- (void)animationDidStart:(CAAnimation *)anim{ + if (self.animationStartBlock) { + self.animationStartBlock(anim); + } +} + +- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ + if (flag && self.animationStopBlock) { + self.animationStopBlock(anim,flag); + } +} + + +@end From ee2ddd84761a3e775c7806864673dee6134ddce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5FFinder=E4=B8=B6Tiwk?= <136652711@qq.com> Date: Wed, 27 Jan 2016 16:47:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?#1.=E4=BF=AE=E5=A4=8D=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E5=88=9A=E5=87=BA=E6=9D=A5=E7=9A=84=E6=97=B6=E5=80=99=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=98=BE=E7=A4=BA=E7=9A=84=E5=8A=A8=E7=94=BB=20#2.?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=87=AA=E5=AE=9A=E4=B9=89=E5=B1=95=E5=BC=80?= =?UTF-8?q?=E7=9A=84ShapeLayer=E7=9A=84=E9=A2=9C=E8=89=B2=20#3.=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8A=A8=E7=94=BB=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E7=9A=84=E6=97=B6=E9=97=B4=20#4.=E6=B7=BB=E5=8A=A0OC?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=9A=84Demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PaperSwitch.h | 12 +-- .../PaperSwitch.m | 100 +++++++++--------- PaperSwitch/PaperSwitchDemo-Bridging-Header.h | 5 + .../PaperSwitchDemo.xcodeproj/project.pbxproj | 24 ++--- .../PaperSwitchDemo/ViewController.swift | 41 +++++-- .../PaperSwitchDemo/ViewController.xib | 6 +- 6 files changed, 104 insertions(+), 84 deletions(-) rename PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.h => PaperSwitch/PaperSwitch.h (67%) rename PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.m => PaperSwitch/PaperSwitch.m (52%) create mode 100644 PaperSwitch/PaperSwitchDemo-Bridging-Header.h diff --git a/PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.h b/PaperSwitch/PaperSwitch.h similarity index 67% rename from PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.h rename to PaperSwitch/PaperSwitch.h index 556f52b..ff40c3b 100644 --- a/PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.h +++ b/PaperSwitch/PaperSwitch.h @@ -1,18 +1,18 @@ // -// FTPaperSwitch.h -// PaperSwitchDemo +// PaperSwitch.h +// XKSCommonSDK // -// Created by _Finder丶Tiwk on 16/1/25. -// Copyright © 2016年 Ramotion. All rights reserved. +// Created by _Finder丶Tiwk on 16/1/26. +// Copyright © 2016年 _Finder丶Tiwk. All rights reserved. // #import -@interface FTPaperSwitch : UISwitch +@interface PaperSwitch : UISwitch /*! 动画时间 默认为0.25秒*/ @property (nonatomic,assign) CFTimeInterval duration; -/*! 展开画面填充颜色,如果不设置,默认为控制底色 绿色*/ +/*! 展开画面填充颜色,如果不设置,为onTintColor 如果onTintColor为空则为绿色*/ @property (nonatomic,strong) UIColor *fillColor; /*! 动画开始回调,从block中的animation参数 可以取到动画相关信息*/ diff --git a/PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.m b/PaperSwitch/PaperSwitch.m similarity index 52% rename from PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.m rename to PaperSwitch/PaperSwitch.m index afe9397..f5e02fc 100644 --- a/PaperSwitchDemo/PaperSwitchDemo/ObjectiveC/FTPaperSwitch.m +++ b/PaperSwitch/PaperSwitch.m @@ -1,27 +1,28 @@ // -// FTPaperSwitch.m -// PaperSwitchDemo +// PaperSwitch.m +// XKSCommonSDK // -// Created by _Finder丶Tiwk on 16/1/25. -// Copyright © 2016年 Ramotion. All rights reserved. +// Created by _Finder丶Tiwk on 16/1/26. +// Copyright © 2016年 _Finder丶Tiwk. All rights reserved. // -#import "FTPaperSwitch.h" +#import "PaperSwitch.h" -static NSString *kShapeLayerName = @"circleShape"; - -@interface FTPaperSwitch () +@interface PaperSwitch () @property (nonatomic,strong) CAShapeLayer *shapLayer; @end -@implementation FTPaperSwitch +@implementation PaperSwitch{ + BOOL _status; /**< Switch开关初始状态*/ + BOOL _codeInit; /**< 是否是通过代码创建的*/ +} #pragma mark - Accessor +static NSString *kShapeLayerName = @"circleShape"; - (CAShapeLayer *)shapLayer{ if (!_shapLayer) { _shapLayer = [CAShapeLayer layer]; _shapLayer.name = kShapeLayerName; - _shapLayer.fillColor = [UIColor greenColor].CGColor; _shapLayer.masksToBounds = YES; } return _shapLayer; @@ -31,52 +32,56 @@ - (CFTimeInterval)duration{ return _duration > 0 ? :0.25; } -- (void)setFillColor:(UIColor *)fillColor{ - _fillColor = fillColor; - self.shapLayer.fillColor = fillColor.CGColor; +- (UIColor *)fillColor{ + return _fillColor? : (self.onTintColor?:[UIColor greenColor]); } #pragma mark - 初始化 -- (instancetype)init{ - self = [super init]; +- (instancetype)initWithFrame:(CGRect)frame{ + self = [super initWithFrame:frame]; if (self) { - [self addTarget:self action:@selector(switchChanged) forControlEvents:UIControlEventValueChanged]; + [self addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; + _codeInit = YES; } return self; } - (void)awakeFromNib{ [super awakeFromNib]; - [self addTarget:self action:@selector(switchChanged) forControlEvents:UIControlEventValueChanged]; + [self addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; + [self.superview.layer insertSublayer:self.shapLayer atIndex:0]; + self.superview.layer.masksToBounds = YES; } #pragma mark - 重写UISwitch设置状态方法 - - (void)setOn:(BOOL)on animated:(BOOL)animated{ [super setOn:on animated:animated]; - [self switchChanged]; + _status = on; } - -- (void)insertIntoSuperLayer{ - BOOL isAdd = NO; - - for (CAShapeLayer *layer in self.superview.layer.sublayers) { - if ([layer.name isEqualToString:kShapeLayerName]) { - isAdd = YES; - break; - } - } - - if (!isAdd) { - [self.superview.layer insertSublayer:self.shapLayer atIndex:0]; - self.superview.layer.masksToBounds = YES; - } +- (CATransform3D)scaleTransform:(BOOL)clockwise{ + CGFloat scale = clockwise?0.0001:1.0; + return CATransform3DMakeScale(scale,scale,scale); } - (void)layoutSubviews{ - [self insertIntoSuperLayer]; + if (_codeInit) { + /* + * 如果是通过代码进行初始化的要等到它加入到SuperView之后, + * 才能找到SuperView为其添加ShapeLayer。 + */ + BOOL added = NO; + for (CAShapeLayer *layer in self.superview.layer.sublayers) { + if ((added = [layer.name isEqualToString:kShapeLayerName])) { + break; + } + } + if (!added) { + [self.superview.layer insertSublayer:self.shapLayer atIndex:0]; + self.superview.layer.masksToBounds = YES; + } + } CGFloat midX = self.center.x; CGFloat midY = self.center.y; @@ -85,28 +90,25 @@ - (void)layoutSubviews{ CGFloat y = MAX(midY, self.superview.frame.size.height - midY); CGFloat radius = sqrt(pow(x, 2) + pow(y, 2)); + self.shapLayer.transform = [self scaleTransform:!_status]; + self.shapLayer.fillColor = self.fillColor.CGColor; self.shapLayer.frame = (CGRect){{midX-radius,midY-radius},{radius*2,radius*2}}; self.shapLayer.anchorPoint = (CGPoint){0.5,0.5}; UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:(CGRect){CGPointZero,{radius*2,radius*2}}]; self.shapLayer.path = bezierPath.CGPath; } -- (void)switchChanged{ - - BOOL status = self.on; - CGFloat orgin = 0.0001; - CGFloat final = 1.0; - - NSValue *value1 = [NSValue valueWithCATransform3D:CATransform3DMakeScale(orgin,orgin,orgin)]; - NSValue *value2 = [NSValue valueWithCATransform3D:CATransform3DMakeScale(final,final,final)]; - NSValue *from = status?value1:value2; - NSValue *to = status?value2:value1; + +- (void)switchChanged:(PaperSwitch *)sender{ + _status = sender.on; + NSValue *from = [NSValue valueWithCATransform3D:[self scaleTransform:_status]]; + NSValue *to = [NSValue valueWithCATransform3D:[self scaleTransform:!_status]]; NSString *animationKey1 = @"ZoomIn"; NSString *animationKey2 = @"ZoomOut"; - NSString *removeKey = status?animationKey2:animationKey1; - NSString *addKey = status?animationKey1:animationKey2; - NSString *timingFunction = status?kCAMediaTimingFunctionEaseIn:kCAMediaTimingFunctionEaseOut; + NSString *removeKey = _status?animationKey2:animationKey1; + NSString *addKey = _status?animationKey1:animationKey2; + NSString *timingFunction = _status?kCAMediaTimingFunctionEaseIn:kCAMediaTimingFunctionEaseOut; [CATransaction begin]; [self.shapLayer removeAnimationForKey:removeKey]; @@ -134,6 +136,4 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ self.animationStopBlock(anim,flag); } } - - @end diff --git a/PaperSwitch/PaperSwitchDemo-Bridging-Header.h b/PaperSwitch/PaperSwitchDemo-Bridging-Header.h new file mode 100644 index 0000000..bfb1b7b --- /dev/null +++ b/PaperSwitch/PaperSwitchDemo-Bridging-Header.h @@ -0,0 +1,5 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import "PaperSwitch.h" \ No newline at end of file diff --git a/PaperSwitchDemo/PaperSwitchDemo.xcodeproj/project.pbxproj b/PaperSwitchDemo/PaperSwitchDemo.xcodeproj/project.pbxproj index d8453c5..f55d806 100644 --- a/PaperSwitchDemo/PaperSwitchDemo.xcodeproj/project.pbxproj +++ b/PaperSwitchDemo/PaperSwitchDemo.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 1DC9AE9D1C5651070035F785 /* FTPaperSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = 1DC9AE9C1C5651070035F785 /* FTPaperSwitch.m */; }; + 1D2EFAB01C58BA7A00948D1A /* PaperSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D2EFAAF1C58BA7A00948D1A /* PaperSwitch.m */; }; 846E0ED31C464B5C0052CDD8 /* Launch.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 846E0ED21C464B5C0052CDD8 /* Launch.storyboard */; }; 9C688A001A274993008BFF1E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C6889FF1A274993008BFF1E /* AppDelegate.swift */; }; 9C688A021A274993008BFF1E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C688A011A274993008BFF1E /* ViewController.swift */; }; @@ -28,8 +28,9 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 1DC9AE9B1C5651070035F785 /* FTPaperSwitch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FTPaperSwitch.h; sourceTree = ""; }; - 1DC9AE9C1C5651070035F785 /* FTPaperSwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FTPaperSwitch.m; sourceTree = ""; }; + 1D2EFAAE1C58BA7A00948D1A /* PaperSwitch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PaperSwitch.h; sourceTree = ""; }; + 1D2EFAAF1C58BA7A00948D1A /* PaperSwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PaperSwitch.m; sourceTree = ""; }; + 1DF9DCBD1C570F1E00EADE5C /* PaperSwitchDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PaperSwitchDemo-Bridging-Header.h"; sourceTree = ""; }; 846E0ED21C464B5C0052CDD8 /* Launch.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Launch.storyboard; sourceTree = ""; }; 9C6889FA1A274993008BFF1E /* PaperSwitchDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PaperSwitchDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9C6889FE1A274993008BFF1E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -61,15 +62,6 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 1DC9AE9A1C5650CA0035F785 /* ObjectiveC */ = { - isa = PBXGroup; - children = ( - 1DC9AE9B1C5651070035F785 /* FTPaperSwitch.h */, - 1DC9AE9C1C5651070035F785 /* FTPaperSwitch.m */, - ); - path = ObjectiveC; - sourceTree = ""; - }; 9C6889F11A274993008BFF1E = { isa = PBXGroup; children = ( @@ -91,7 +83,6 @@ 9C6889FC1A274993008BFF1E /* PaperSwitchDemo */ = { isa = PBXGroup; children = ( - 1DC9AE9A1C5650CA0035F785 /* ObjectiveC */, 9C688A211A274A39008BFF1E /* PaperSwitch */, 9C6889FF1A274993008BFF1E /* AppDelegate.swift */, 9C688A011A274993008BFF1E /* ViewController.swift */, @@ -131,7 +122,10 @@ 9C688A211A274A39008BFF1E /* PaperSwitch */ = { isa = PBXGroup; children = ( + 1D2EFAAE1C58BA7A00948D1A /* PaperSwitch.h */, + 1D2EFAAF1C58BA7A00948D1A /* PaperSwitch.m */, 9C688A221A274A39008BFF1E /* RAMPaperSwitch.swift */, + 1DF9DCBD1C570F1E00EADE5C /* PaperSwitchDemo-Bridging-Header.h */, ); name = PaperSwitch; path = ../../PaperSwitch; @@ -241,7 +235,7 @@ files = ( 9C688A021A274993008BFF1E /* ViewController.swift in Sources */, 9C688A231A274A39008BFF1E /* RAMPaperSwitch.swift in Sources */, - 1DC9AE9D1C5651070035F785 /* FTPaperSwitch.m in Sources */, + 1D2EFAB01C58BA7A00948D1A /* PaperSwitch.m in Sources */, 9C688A001A274993008BFF1E /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -355,6 +349,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "ramotion.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "/Users/huafan/Desktop/GithubRepository/paper-switch/PaperSwitch/PaperSwitchDemo-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; @@ -369,6 +364,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "ramotion.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "/Users/huafan/Desktop/GithubRepository/paper-switch/PaperSwitch/PaperSwitchDemo-Bridging-Header.h"; }; name = Release; }; diff --git a/PaperSwitchDemo/PaperSwitchDemo/ViewController.swift b/PaperSwitchDemo/PaperSwitchDemo/ViewController.swift index af18954..33294c2 100644 --- a/PaperSwitchDemo/PaperSwitchDemo/ViewController.swift +++ b/PaperSwitchDemo/PaperSwitchDemo/ViewController.swift @@ -22,15 +22,19 @@ import UIKit + class ViewController: UIViewController { @IBOutlet weak private var connectContactsLabel: UILabel! @IBOutlet weak private var phone1ImageView: UIImageView! - @IBOutlet weak private var paperSwitch1: RAMPaperSwitch! +// @IBOutlet weak private var paperSwitch1: RAMPaperSwitch! + @IBOutlet weak private var paperSwitch1: PaperSwitch! @IBOutlet weak private var allowDiscoveryLabel: UILabel! @IBOutlet weak private var phone2ImageView: UIImageView! - @IBOutlet weak private var paperSwitch2: RAMPaperSwitch! +// @IBOutlet weak private var paperSwitch2: RAMPaperSwitch! + @IBOutlet weak private var paperSwitch2: PaperSwitch! + override func viewDidLoad() { @@ -38,24 +42,39 @@ class ViewController: UIViewController { // Do any additional setup after loading the view, typically from a nib. self.setupPaperSwitch() + self.navigationController?.navigationBarHidden = true } + private func setupPaperSwitch() { - - self.paperSwitch1.animationDidStartClosure = {(onAnimation: Bool) in - - self.animateLabel(self.connectContactsLabel, onAnimation: onAnimation, duration: self.paperSwitch1.duration) - self.animateImageView(self.phone1ImageView, onAnimation: onAnimation, duration: self.paperSwitch1.duration) + paperSwitch1.animationStartBlock = { (animation:CAAnimation!) in + print("111111111111") + self.animateLabel(self.connectContactsLabel, onAnimation: true, duration: animation.duration) + self.animateImageView(self.phone1ImageView, onAnimation: true, duration: animation.duration) + } - - self.paperSwitch2.animationDidStartClosure = {(onAnimation: Bool) in + paperSwitch2.animationStartBlock = { (animation:CAAnimation!) in + print("2222222222222") + self.animateLabel(self.allowDiscoveryLabel, onAnimation: true, duration: animation.duration) + self.animateImageView(self.phone2ImageView, onAnimation: true, duration: animation.duration) - self.animateLabel(self.self.allowDiscoveryLabel, onAnimation: onAnimation, duration: self.paperSwitch2.duration) - self.animateImageView(self.phone2ImageView, onAnimation: onAnimation, duration: self.paperSwitch2.duration) } + +// self.paperSwitch1.animationDidStartClosure = {(onAnimation: Bool) in +// +// self.animateLabel(self.connectContactsLabel, onAnimation: onAnimation, duration: self.paperSwitch1.duration) +// self.animateImageView(self.phone1ImageView, onAnimation: onAnimation, duration: self.paperSwitch1.duration) +// } +// +// +// self.paperSwitch2.animationDidStartClosure = {(onAnimation: Bool) in +// +// self.animateLabel(self.self.allowDiscoveryLabel, onAnimation: onAnimation, duration: self.paperSwitch2.duration) +// self.animateImageView(self.phone2ImageView, onAnimation: onAnimation, duration: self.paperSwitch2.duration) +// } } diff --git a/PaperSwitchDemo/PaperSwitchDemo/ViewController.xib b/PaperSwitchDemo/PaperSwitchDemo/ViewController.xib index 015f72e..265d75b 100644 --- a/PaperSwitchDemo/PaperSwitchDemo/ViewController.xib +++ b/PaperSwitchDemo/PaperSwitchDemo/ViewController.xib @@ -1,5 +1,5 @@ - + @@ -67,7 +67,7 @@ added to your friends list. - + @@ -125,7 +125,7 @@ added to your friends list. - +