Skip to content

Commit

Permalink
为同时兼容Swift4.0和Swift4.2而做的优化处理。
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsoft authored and oubaiquan committed Sep 21, 2018
1 parent f271ae1 commit 0dfee7c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

---

## [V1.3.0](https://github.com/youngsoft/TangramKit/releases/tag/1.3.0)(2018/09/29)
## [V1.3.1](https://github.com/youngsoft/TangramKit/releases/tag/1.3.1)(2018/09/21)
#### Fixed
1. 为实现对Swift4.0的支持而修复了所有编译告警的问题
1. 为实现对Swift4.0/4.2的支持而修复了所有编译告警的问题
2. 修复了浮动布局TGFloatLayout中的子视图在设置尺寸为TGWeight类型时的一个比例计算的错误问题。
3. 实现对iPhoneXR、iPhoneXS、iPhoneXSMAX的tg_padding的安全区缩进的改进支持。
4. 实现了在Application Extension中使用布局库时报UIApplication对象不支持或者不存在的问题。
Expand Down
2 changes: 1 addition & 1 deletion TangramKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "TangramKit"
s.version = "1.3.0"
s.version = "1.3.1"
s.summary = "TangramKit is A powerful iOS UI framework. It integrated the Android layout,AutoLayout,SizeClass, HTML/CSS float and flexbox functions."

s.description = <<-DESC
Expand Down
4 changes: 2 additions & 2 deletions TangramKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 4.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -862,7 +862,7 @@
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 4.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down
44 changes: 42 additions & 2 deletions TangramKit/TGBaseLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass {
/// - target: 事件的处理对象,如果设置为nil则表示取消事件。
/// - action: 事件的处理动作,格式为:func handleAction(sender:TGBaseLayout)
/// - controlEvents: 支持的事件类型,目前只支持:touchDown、touchUpInside、touchCancel这三个事件。
#if swift(>=4.2)
public func tg_setTarget(_ target: NSObjectProtocol?, action: Selector?, for controlEvents: UIControl.Event)
{
if _tgTouchEventDelegate == nil
Expand All @@ -1393,6 +1394,19 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass {

_tgTouchEventDelegate?.setTarget(target, action: action, for: controlEvents)
}
#else
public func tg_setTarget(_ target: NSObjectProtocol?, action: Selector?, for controlEvents: UIControlEvents)
{


if _tgTouchEventDelegate == nil
{
_tgTouchEventDelegate = TGTouchEventDelegate(self)
}

_tgTouchEventDelegate?.setTarget(target, action: action, for: controlEvents)
}
#endif

/**
设置布局按下时背景的高亮的颜色。只有设置了tg_setTarget方法后此属性才生效。
Expand Down Expand Up @@ -2018,13 +2032,13 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass {
if let t = lsc.width.sizeVal
{
//约束冲突:宽度依赖的视图不是父视图
assert(t.view == newSuperview, "Constraint exception!! \(self)width dependent on:\(t.view) is not superview")
assert(t.view == newSuperview, "Constraint exception!! \(self)width dependent on:\(t.view!) is not superview")
}

if let t = lsc.height.sizeVal
{
//约束冲突:高度依赖的视图不是父视图
assert(t.view == newSuperview, "Constraint exception!! \(self)height dependent on:\(t.view) is not superview")
assert(t.view == newSuperview, "Constraint exception!! \(self)height dependent on:\(t.view!) is not superview")
}

#endif
Expand Down Expand Up @@ -3574,6 +3588,8 @@ private class TGTouchEventDelegate
TGTouchEventDelegate._CurrentLayout = nil
}

#if swift(>=4.2)

func setTarget(_ target: NSObjectProtocol?, action: Selector?, for controlEvents: UIControl.Event)
{
//just only support these events
Expand All @@ -3595,6 +3611,30 @@ private class TGTouchEventDelegate
}

}
#else

func setTarget(_ target: NSObjectProtocol?, action: Selector?, for controlEvents: UIControlEvents)
{
//just only support these events
switch controlEvents {
case UIControlEvents.touchDown:
_touchDownTarget = target
_touchDownAction = action
break
case UIControlEvents.touchUpInside:
_touchUpTarget = target
_touchUpAction = action
break
case UIControlEvents.touchCancel:
_touchCancelTarget = target
_touchCancelAction = action
break
default:
return
}
}

#endif

func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
Expand Down
12 changes: 12 additions & 0 deletions TangramKit/TGPathLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,24 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass {
}
}

#if swift(>=4.2)

open override func sendSubviewToBack(_ view: UIView) {
if tg_originView == view {
return
}
super.sendSubviewToBack(view)
}

#else

open override func sendSubview(toBack view: UIView) {
if tg_originView == view {
return
}
super.sendSubview(toBack: view)
}
#endif

open override func willRemoveSubview(_ subview: UIView) {
super.willRemoveSubview(subview)
Expand Down
2 changes: 1 addition & 1 deletion TangramKit/TangramKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*/

//Current version is 1.3.0, please open: https://github.com/youngsoft/TangramKit/blob/master/CHANGELOG.md to show the changes.
//Current version is 1.3.1, please open: https://github.com/youngsoft/TangramKit/blob/master/CHANGELOG.md to show the changes.



Expand Down

0 comments on commit 0dfee7c

Please sign in to comment.