diff --git a/CHANGELOG.md b/CHANGELOG.md index c7064e0..1a0fe43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ **TangramKit**中的所有历史版本变化将会在这个文件中列出。 --- +## [V1.1.5](https://github.com/youngsoft/TangramKit/releases/tag/1.1.5)(2018/05/06) + +1. 优化了编译时慢的一些代码。 +2. 修复表格布局的行的尺寸设置为TGLayoutSize.wrap时并且同时使用了智能边界线时,其中的列子视图的边界线显示不完整的问题。 + ## [V1.1.4](https://github.com/youngsoft/TangramKit/releases/tag/1.1.4)(2018/04/23) diff --git a/README.md b/README.md index f3c5854..967a0b1 100644 --- a/README.md +++ b/README.md @@ -587,7 +587,7 @@ To integrate TangramKit into your Xcode project using CocoaPods, specify it in y source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' -pod 'TangramKit', '~> 1.1.4' +pod 'TangramKit' ``` Then, run the following command: diff --git a/README.zh.md b/README.zh.md index 5792ecd..4fa216a 100644 --- a/README.zh.md +++ b/README.zh.md @@ -590,7 +590,7 @@ $ gem install cocoapods source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' -pod 'TangramKit', '~> 1.1.4' +pod 'TangramKit' ``` 然后运行如下命令: diff --git a/TangramKit.podspec b/TangramKit.podspec index c301cfb..bdaf903 100644 --- a/TangramKit.podspec +++ b/TangramKit.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "TangramKit" - s.version = "1.1.4" + s.version = "1.1.5" 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 diff --git a/TangramKit.xcodeproj/project.pbxproj b/TangramKit.xcodeproj/project.pbxproj index 2ce6c0d..9ec55d7 100644 --- a/TangramKit.xcodeproj/project.pbxproj +++ b/TangramKit.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ 1890A2251EDF96C800D61C1A /* TGRelativeLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 681BD90C1E0B92E100403A1F /* TGRelativeLayout.swift */; }; 1890A2261EDF96C800D61C1A /* TGTableLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 681BD90D1E0B92E100403A1F /* TGTableLayout.swift */; }; 18BCBD461E1336D900AC7766 /* AllTest8ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18BCBD451E1336D900AC7766 /* AllTest8ViewController.swift */; }; + 204DC323209E0BC000F6CB57 /* TLTest4ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 204DC322209E0BC000F6CB57 /* TLTest4ViewController.swift */; }; 20B6C6E71FA40AEC001D51C7 /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20B6C6E61FA40AEC001D51C7 /* DetailViewController.swift */; }; 20DCF335208CD022007A879B /* FOLTest7ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20DCF334208CD022007A879B /* FOLTest7ViewController.swift */; }; 681BD8DF1E0B91A500403A1F /* TangramKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 681BD8DD1E0B91A500403A1F /* TangramKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -102,6 +103,7 @@ 18270C241C954B3C00CBCC92 /* TangramKitDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TangramKitDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 184243071E327F0800E2CCE1 /* FLLTest5ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FLLTest5ViewController.swift; sourceTree = ""; }; 18BCBD451E1336D900AC7766 /* AllTest8ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AllTest8ViewController.swift; sourceTree = ""; }; + 204DC322209E0BC000F6CB57 /* TLTest4ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TLTest4ViewController.swift; sourceTree = ""; }; 20B6C6E61FA40AEC001D51C7 /* DetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = ""; }; 20DCF334208CD022007A879B /* FOLTest7ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FOLTest7ViewController.swift; sourceTree = ""; }; 681BD8DB1E0B91A500403A1F /* TangramKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TangramKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -385,6 +387,7 @@ 68F036381E0B7D2700CEBAEF /* TLTest1ViewController.swift */, 68F036391E0B7D2700CEBAEF /* TLTest2ViewController.swift */, 68F0363A1E0B7D2700CEBAEF /* TLTest3ViewController.swift */, + 204DC322209E0BC000F6CB57 /* TLTest4ViewController.swift */, ); path = TableLayoutDemo; sourceTree = ""; @@ -450,7 +453,7 @@ TargetAttributes = { 18270C231C954B3C00CBCC92 = { CreatedOnToolsVersion = 7.2; - DevelopmentTeam = Q5MFLFRY64; + DevelopmentTeam = BGQ8WB468K; LastSwiftMigration = 0900; SystemCapabilities = { com.apple.BackgroundModes = { @@ -559,6 +562,7 @@ 68F0366A1E0B7D2700CEBAEF /* LLTest4ViewController.swift in Sources */, 68F036521E0B7D2700CEBAEF /* AllTest4ViewController.swift in Sources */, 68F036411E0B7D2700CEBAEF /* FOLTest2ViewController.swift in Sources */, + 204DC323209E0BC000F6CB57 /* TLTest4ViewController.swift in Sources */, 68F036531E0B7D2700CEBAEF /* AllTest5ViewController.swift in Sources */, 68F036671E0B7D2700CEBAEF /* LLTest1ViewController.swift in Sources */, 68F036461E0B7D2700CEBAEF /* FOLTest6ViewController.swift in Sources */, @@ -750,7 +754,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - DEVELOPMENT_TEAM = Q5MFLFRY64; + DEVELOPMENT_TEAM = BGQ8WB468K; FRAMEWORK_SEARCH_PATHS = ""; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = TangramKit/TangramKitDemo/TangramKitPrefix.pch; @@ -771,7 +775,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - DEVELOPMENT_TEAM = Q5MFLFRY64; + DEVELOPMENT_TEAM = BGQ8WB468K; FRAMEWORK_SEARCH_PATHS = ""; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = TangramKit/TangramKitDemo/TangramKitPrefix.pch; diff --git a/TangramKit/Info.plist b/TangramKit/Info.plist index 58241b6..154313d 100644 --- a/TangramKit/Info.plist +++ b/TangramKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.1.3 + 1.1.5 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/TangramKit/TGBaseLayout.swift b/TangramKit/TGBaseLayout.swift index 85a0f04..6319cf9 100644 --- a/TangramKit/TGBaseLayout.swift +++ b/TangramKit/TGBaseLayout.swift @@ -379,7 +379,7 @@ extension UIView:TGViewSizeClass sc.tg_visibility = newValue switch newValue { - case .visible: + case TGVisibility.visible: self.isHidden = false break default: @@ -1035,7 +1035,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { /** 把一个布局视图放入到UIScrollView(UITableView和UICollectionView除外)内时是否自动调整UIScrollView的contentSize值。默认是.auto表示布局视图会自动接管UIScrollView的contentSize的值。 你可以将这个属性设置.no而不调整和控制contentSize的值,设置为.yes则一定会调整contentSize. */ - public var tg_adjustScrollViewContentSizeMode:TGAdjustScrollViewContentSizeMode = .auto + public var tg_adjustScrollViewContentSizeMode:TGAdjustScrollViewContentSizeMode = TGAdjustScrollViewContentSizeMode.auto /** 在布局视图进行布局时是否调用基类的layoutSubviews方法,默认设置为false。 @@ -1103,7 +1103,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { /// - size: 希望的尺寸 /// - type: size class的类型,他表示评估某个sizeClass下的尺寸值,如果没有找到指定的sizeClass则会根据继承规则得到最合适的sizeClass /// - Returns: 评估后的尺寸 - public func tg_sizeThatFits(_ size:CGSize = .zero, inSizeClass type:TGSizeClassType = .default) -> CGSize + public func tg_sizeThatFits(_ size:CGSize = CGSize.zero, inSizeClass type:TGSizeClassType = TGSizeClassType.default) -> CGSize { return self.tgSizeThatFits(size:size,sbs:nil, inSizeClass: type) } @@ -1178,7 +1178,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { - size:指定布局视图期望的宽度或者高度,一般请将这个值设置为.zero。 具体请参考tg_sizeThatFits方法中的size的说明。 - Returns: 子视图在布局视图最后一个位置(假如加入后)的frame值。 */ - public func tg_estimatedFrame(of subview:UIView, inLayoutSize size:CGSize = .zero) -> CGRect + public func tg_estimatedFrame(of subview:UIView, inLayoutSize size:CGSize = CGSize.zero) -> CGRect { if subview.superview != nil && subview.superview! === self { @@ -1188,7 +1188,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { var sbs = self.tgGetLayoutSubviews() sbs.append(subview) - let _ = self.tgSizeThatFits(size: size, sbs: sbs, inSizeClass: .default) + let _ = self.tgSizeThatFits(size: size, sbs: sbs, inSizeClass: TGSizeClassType.default) return subview.tg_estimatedFrame } @@ -1233,7 +1233,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { { if _tgBorderlineLayerDelegate == nil { - _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self) + _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self.layer) } _tgBorderlineLayerDelegate.topBorderline = newValue @@ -1250,7 +1250,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { { if _tgBorderlineLayerDelegate == nil { - _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self) + _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self.layer) } _tgBorderlineLayerDelegate.leadingBorderline = newValue @@ -1267,7 +1267,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { { if _tgBorderlineLayerDelegate == nil { - _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self) + _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self.layer) } _tgBorderlineLayerDelegate.bottomBorderline = newValue @@ -1284,7 +1284,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { { if _tgBorderlineLayerDelegate == nil { - _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self) + _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self.layer) } _tgBorderlineLayerDelegate.trailingBorderline = newValue @@ -1303,7 +1303,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { { if _tgBorderlineLayerDelegate == nil { - _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self) + _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self.layer) } _tgBorderlineLayerDelegate.leftBorderline = newValue @@ -1321,7 +1321,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { { if _tgBorderlineLayerDelegate == nil { - _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self) + _tgBorderlineLayerDelegate = TGBorderlineLayerDelegate(self.layer) } _tgBorderlineLayerDelegate.rightBorderline = newValue @@ -1470,8 +1470,8 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { let sizeClassType = TGBaseLayout.tgGetGlobalSizeClassType(layoutv: self) switch sizeClassType { - case .comb(_, _, let screen): - if screen == .portrait + case TGSizeClassType.comb(_, _, let screen): + if screen == TGSizeClassType.Screen.portrait { currentScreenOrientation = 1 } @@ -1509,7 +1509,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { let oldSelfSize = self.bounds.size var newSelfSize:CGSize - if _tgUseCacheRects && tgFrame.width != .greatestFiniteMagnitude && tgFrame.height != .greatestFiniteMagnitude + if _tgUseCacheRects && tgFrame.width != CGFloat.greatestFiniteMagnitude && tgFrame.height != CGFloat.greatestFiniteMagnitude { newSelfSize = CGSize(width: tgFrame.width, height: tgFrame.height) } @@ -1525,8 +1525,8 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { { let (sbvtgFrame, sbvsc) = self.tgGetSubviewFrameAndSizeClass(sbv) - let sbvOldBounds = sbv.bounds - let sbvOldCenter = sbv.center + let sbvOldBounds:CGRect = sbv.bounds + let sbvOldCenter:CGPoint = sbv.center if sbvtgFrame.leading != CGFloat.greatestFiniteMagnitude && sbvtgFrame.top != CGFloat.greatestFiniteMagnitude && !sbvsc.tg_noLayout && !sbvsc.tg_useFrame { @@ -1550,7 +1550,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { { rc = _tgRoundRectForLayout(sbvtgFrame.frame) - var sbvTempBounds = CGRect(origin:sbvOldBounds.origin, size:rc.size) + var sbvTempBounds:CGRect = CGRect(origin:sbvOldBounds.origin, size:rc.size) if (_tgCGFloatErrorEqual(sbvTempBounds.size.width, sbvOldBounds.size.width, _tgrSizeError)) { @@ -1600,9 +1600,9 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { } - if sbvsc.tg_visibility == .gone && !sbv.isHidden + if sbvsc.tg_visibility == TGVisibility.gone && !sbv.isHidden { - sbv.bounds = CGRect(origin: sbvOldBounds.origin, size: .zero) + sbv.bounds = CGRect(origin: sbvOldBounds.origin, size: CGSize.zero) } @@ -1688,12 +1688,24 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { } - _tgBorderlineLayerDelegate?.setNeedsLayout() if newSelfSize.width != CGFloat.greatestFiniteMagnitude { let supv:UIView! = self.superview + + if _tgBorderlineLayerDelegate != nil + { + var borderlineRect = CGRect(x: 0, y: 0, width: newSelfSize.width, height: newSelfSize.height) + if let supvlayout = supv as? TGBaseLayout + { + //这里给父布局视图一个机会来可以改变当前布局的borderlineRect的值,也就是显示的边界线有可能会超出当前布局视图本身的区域。 + //比如一些表格或者其他的情况。默认情况下这个函数什么也不做。 + supvlayout.tgHook(sublayout: self, borderlineRect: &borderlineRect) + } + + _tgBorderlineLayerDelegate.setNeedsLayout(borderlineRect) + } //如果自己的父视图是非UIScrollView以及非布局视图。以及自己的宽度是.wrap或者高度是.wrap时,并且如果设置了在父视图居中或者居下或者居右时要在父视图中更新自己的位置。 if supv != nil && !supv.isKind(of: TGBaseLayout.self) @@ -1777,10 +1789,10 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { let suplsc = supv.tgCurrentSizeClass as! TGViewSizeClassImpl - let selftgTopMargin = lsc.top.absPos - let selftgBottomMargin = lsc.bottom.absPos - let selftgLeadingMargin = lsc.leading.absPos - let selftgTrailingMargin = lsc.trailing.absPos + let selftgTopMargin:CGFloat = lsc.top.absPos + let selftgBottomMargin:CGFloat = lsc.bottom.absPos + let selftgLeadingMargin:CGFloat = lsc.leading.absPos + let selftgTrailingMargin:CGFloat = lsc.trailing.absPos if suplsc.isSomeSizeWrap { @@ -1862,7 +1874,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { { if !self.isHidden { - _tgBorderlineLayerDelegate?.setNeedsLayout() + _tgBorderlineLayerDelegate?.setNeedsLayout(CGRect(x:0, y:0, width:self.bounds.width, height:self.bounds.height)) if (self.superview as? TGBaseLayout) != nil { @@ -1908,7 +1920,7 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { if (newSuperview != nil) { - let defRectEdge:UIRectEdge = [.left, .right] + let defRectEdge:UIRectEdge = [UIRectEdge.left, UIRectEdge.right] if self.value(forKey: "viewDelegate") != nil { if lsc.width.isWrap @@ -1923,17 +1935,17 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { if lsc.tg_insetsPaddingFromSafeArea.rawValue == defRectEdge.rawValue { - lsc.tg_insetsPaddingFromSafeArea = [.left, .right, .bottom] + lsc.tg_insetsPaddingFromSafeArea = [UIRectEdge.left, UIRectEdge.right, UIRectEdge.bottom] } - self.tg_adjustScrollViewContentSizeMode = .no + self.tg_adjustScrollViewContentSizeMode = TGAdjustScrollViewContentSizeMode.no } if ((newSuperview as? UIScrollView) != nil && (newSuperview as? UITableView) == nil && (newSuperview as? UICollectionView) == nil) { if lsc.tg_insetsPaddingFromSafeArea.rawValue == defRectEdge.rawValue { - lsc.tg_insetsPaddingFromSafeArea = [.left, .right, .bottom] + lsc.tg_insetsPaddingFromSafeArea = [UIRectEdge.left, UIRectEdge.right, UIRectEdge.bottom] } } @@ -2039,20 +2051,20 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { //不支持放在UITableView和UICollectionView下,因为有肯能是tableheaderView或者section下。 if ((newSuperview as? UIScrollView) != nil && (newSuperview as? UITableView) == nil && (newSuperview as? UICollectionView) == nil) { - if self.tg_adjustScrollViewContentSizeMode == .auto + if self.tg_adjustScrollViewContentSizeMode == TGAdjustScrollViewContentSizeMode.auto { //这里预先设置一下contentSize主要是为了解决contentOffset在后续计算contentSize的偏移错误的问题。 UIView.performWithoutAnimation { // UIScrollView *scrollSuperView = (UIScrollView*)newSuperview; - if let scrollSuperView = newSuperview as? UIScrollView, scrollSuperView.contentSize.equalTo(.zero) + if let scrollSuperView = newSuperview as? UIScrollView, scrollSuperView.contentSize.equalTo(CGSize.zero) { let screenSize = UIScreen.main.bounds.size scrollSuperView.contentSize = CGSize(width:0, height:screenSize.height + 0.1) } } - self.tg_adjustScrollViewContentSizeMode = .yes + self.tg_adjustScrollViewContentSizeMode = TGAdjustScrollViewContentSizeMode.yes } } } @@ -2181,6 +2193,11 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { return TGLayoutViewSizeClassImpl(view:self) } + internal func tgHook(sublayout:TGBaseLayout, borderlineRect: inout CGRect) + { + //do nothing... + } + //MARK:private var //边界线处理的代理对象。 @@ -2231,8 +2248,8 @@ extension TGBaseLayout if sbvButton.titleLabel != nil { //得到按钮本身的高度,以及单行文本的高度,这样就能算出按钮和文本的间距 - let buttonSize = sbvButton.sizeThatFits(.zero) - let buttonTitleSize = sbvButton.titleLabel!.sizeThatFits(.zero) + let buttonSize = sbvButton.sizeThatFits(CGSize.zero) + let buttonTitleSize = sbvButton.titleLabel!.sizeThatFits(CGSize.zero) let sz = sbvButton.titleLabel!.sizeThatFits(CGSize(width: width, height: 0)) h = sz.height + buttonSize.height - buttonTitleSize.height //这个sz只是纯文本的高度,所以要加上原先按钮和文本的高度差。。 @@ -2800,7 +2817,7 @@ extension TGBaseLayout fileprivate func tgAlterScrollViewContentSize(_ newSize:CGSize, lsc:TGViewSizeClassImpl) { - if let scrolv = self.superview as? UIScrollView , self.tg_adjustScrollViewContentSizeMode == .yes + if let scrolv = self.superview as? UIScrollView , self.tg_adjustScrollViewContentSizeMode == TGAdjustScrollViewContentSizeMode.yes { var contSize = scrolv.contentSize let rectSuper = scrolv.bounds @@ -2936,10 +2953,10 @@ extension TGBaseLayout { let sbvVertAlignment = sbvsc.tg_alignment & TGGravity.horz.mask var sbvVertGravity:TGGravity = TGGravity.vert.top - if vertGravity != .none + if vertGravity != TGGravity.none { sbvVertGravity = vertGravity - if sbvVertAlignment != .none + if sbvVertAlignment != TGGravity.none { sbvVertGravity = sbvVertAlignment } @@ -2947,7 +2964,7 @@ extension TGBaseLayout else { - if sbvVertAlignment != .none + if sbvVertAlignment != TGGravity.none { sbvVertGravity = sbvVertAlignment } @@ -3041,10 +3058,10 @@ extension TGBaseLayout { let sbvHorzAligement = self.tgConvertLeftRightGravityToLeadingTrailing(sbvsc.tg_alignment & TGGravity.vert.mask) var sbvHorzGravity:TGGravity = TGGravity.horz.leading - if horzGravity != .none + if horzGravity != TGGravity.none { sbvHorzGravity = horzGravity - if sbvHorzAligement != .none + if sbvHorzAligement != TGGravity.none { sbvHorzGravity = sbvHorzAligement } @@ -3052,7 +3069,7 @@ extension TGBaseLayout else { - if sbvHorzAligement != .none + if sbvHorzAligement != TGGravity.none { sbvHorzGravity = sbvHorzAligement } @@ -3135,12 +3152,12 @@ extension TGBaseLayout //如果当前是隐藏的 if sbv.isHidden { - return sbvsc.tg_visibility != .invisible + return sbvsc.tg_visibility != TGVisibility.invisible } else { //如果是未隐藏则如何是设置是.gone则不参与布局,否则就参与布局 - return sbvsc.tg_visibility == .gone + return sbvsc.tg_visibility == TGVisibility.gone } } @@ -3247,7 +3264,7 @@ extension TGBaseLayout //最终的结果是非布局视图的宽度是wrap的情况下适用。 if (sbv as? TGBaseLayout) == nil && sbvsc.width.isWrap { - let fitSize = sbv.sizeThatFits(.zero) + let fitSize = sbv.sizeThatFits(CGSize.zero) sbvtgFrame.width = sbvsc.width.measure(fitSize.width) if sbvsc.height.isWrap { @@ -3323,49 +3340,49 @@ extension TGBaseLayout if _stgSizeClassType == nil || (layoutv.superview as? TGBaseLayout) == nil { //得到最佳的sizeClass - var sizeClassWidthType:TGSizeClassType.Width = .any - var sizeClassHeightType:TGSizeClassType.Height = .any + var sizeClassWidthType:TGSizeClassType.Width = TGSizeClassType.Width.any + var sizeClassHeightType:TGSizeClassType.Height = TGSizeClassType.Height.any var sizeClassScreenType:TGSizeClassType.Screen? = nil if #available(iOS 8.0, *) { switch layoutv.traitCollection.verticalSizeClass { - case .compact: - sizeClassHeightType = .compact + case UIUserInterfaceSizeClass.compact: + sizeClassHeightType = TGSizeClassType.Height.compact break - case .regular: - sizeClassHeightType = .regular + case UIUserInterfaceSizeClass.regular: + sizeClassHeightType = TGSizeClassType.Height.regular break default: - sizeClassHeightType = .any + sizeClassHeightType = TGSizeClassType.Height.any } switch layoutv.traitCollection.horizontalSizeClass { - case .compact: - sizeClassWidthType = .compact + case UIUserInterfaceSizeClass.compact: + sizeClassWidthType = TGSizeClassType.Width.compact break - case .regular: - sizeClassWidthType = .regular + case UIUserInterfaceSizeClass.regular: + sizeClassWidthType = TGSizeClassType.Width.regular break default: - sizeClassWidthType = .any + sizeClassWidthType = TGSizeClassType.Width.any } } let devori = UIDevice.current.orientation if UIDeviceOrientationIsPortrait(devori) { - sizeClassScreenType = .portrait + sizeClassScreenType = TGSizeClassType.Screen.portrait } else if UIDeviceOrientationIsLandscape(devori) { - sizeClassScreenType = .landscape + sizeClassScreenType = TGSizeClassType.Screen.landscape } else { - sizeClassScreenType = .portrait + sizeClassScreenType = TGSizeClassType.Screen.portrait } @@ -3438,8 +3455,6 @@ extension TGBaseLayout } } - - } //管理触摸事件的代理类。 @@ -3462,7 +3477,7 @@ private class TGTouchEventDelegate private var _forbidTouch:Bool = false private var _canCallAction:Bool = false - private var _beginPoint:CGPoint = .zero + private var _beginPoint:CGPoint = CGPoint.zero static var _HasBegin:Bool = false static weak var _CurrentLayout:TGBaseLayout! = nil @@ -3658,17 +3673,18 @@ private class TGTouchEventDelegate class TGBorderlineLayerDelegate:NSObject,CALayerDelegate { - private weak var _layout:TGBaseLayout! + private var _layoutRect:CGRect! = nil + private weak var _layoutLayer:CALayer! private weak var _topBorderlineLayer:CAShapeLayer! = nil private weak var _leadingBorderlineLayer:CAShapeLayer! = nil private weak var _bottomBorderlineLayer:CAShapeLayer! = nil private weak var _trailingBorderlineLayer:CAShapeLayer! = nil - convenience init(_ layout:TGBaseLayout) { + convenience init(_ layoutLayer:CALayer) { self.init() - _layout = layout + _layoutLayer = layoutLayer } deinit { @@ -3785,8 +3801,9 @@ class TGBorderlineLayerDelegate:NSObject,CALayerDelegate } - func setNeedsLayout() + func setNeedsLayout(_ layoutRect:CGRect!) { + _layoutRect = layoutRect if _topBorderlineLayer != nil { _topBorderlineLayer.setNeedsLayout() @@ -3812,12 +3829,13 @@ class TGBorderlineLayerDelegate:NSObject,CALayerDelegate func layoutSublayers(of layer: CALayer) { - if _layout == nil + if _layoutLayer == nil || _layoutRect == nil { return } - let layoutSize:CGSize = self._layout.bounds.size + let layoutSize:CGSize = _layoutRect.size + let layoutPoint:CGPoint = _layoutRect.origin if layoutSize.height == 0 || layoutSize.width == 0 { return @@ -3830,27 +3848,39 @@ class TGBorderlineLayerDelegate:NSObject,CALayerDelegate if _leadingBorderlineLayer != nil && layer === _leadingBorderlineLayer { - layerRect = CGRect(x: leadingBorderline.offset, y: leadingBorderline.headIndent, width: leadingBorderline.thick/scale, height: layoutSize.height - leadingBorderline.headIndent - leadingBorderline.tailIndent); + layerRect = CGRect(x: leadingBorderline.offset + layoutPoint.x, + y: leadingBorderline.headIndent + layoutPoint.y, + width: leadingBorderline.thick/scale, + height: layoutSize.height - leadingBorderline.headIndent - leadingBorderline.tailIndent); fromPoint = CGPoint(x: 0, y: 0); toPoint = CGPoint(x: 0, y: layerRect.size.height); } else if _trailingBorderlineLayer != nil && layer === _trailingBorderlineLayer { - layerRect = CGRect(x: layoutSize.width - trailingBorderline.thick / scale - trailingBorderline.offset, y: trailingBorderline.headIndent, width: trailingBorderline.thick / scale, height: layoutSize.height - trailingBorderline.headIndent - trailingBorderline.tailIndent); + layerRect = CGRect(x: layoutSize.width - trailingBorderline.thick / scale - trailingBorderline.offset + layoutPoint.x, + y: trailingBorderline.headIndent + layoutPoint.y, + width: trailingBorderline.thick / scale, + height: layoutSize.height - trailingBorderline.headIndent - trailingBorderline.tailIndent); fromPoint = CGPoint(x: 0, y: 0); toPoint = CGPoint(x: 0, y: layerRect.size.height); } else if _topBorderlineLayer != nil && layer === _topBorderlineLayer { - layerRect = CGRect(x: topBorderline.headIndent, y: topBorderline.offset, width: layoutSize.width - topBorderline.headIndent - topBorderline.tailIndent, height: topBorderline.thick/scale); + layerRect = CGRect(x: topBorderline.headIndent + layoutPoint.x, + y: topBorderline.offset + layoutPoint.y, + width: layoutSize.width - topBorderline.headIndent - topBorderline.tailIndent, + height: topBorderline.thick/scale); fromPoint = CGPoint(x: 0, y: 0); toPoint = CGPoint(x: layerRect.size.width, y: 0); } else if _bottomBorderlineLayer != nil && layer === _bottomBorderlineLayer { - layerRect = CGRect(x:bottomBorderline.headIndent, y: layoutSize.height - bottomBorderline.thick/scale - bottomBorderline.offset, width: layoutSize.width - bottomBorderline.headIndent - bottomBorderline.tailIndent, height: bottomBorderline.thick / scale); + layerRect = CGRect(x:bottomBorderline.headIndent + layoutPoint.x, + y: layoutSize.height - bottomBorderline.thick/scale - bottomBorderline.offset + layoutPoint.y, + width: layoutSize.width - bottomBorderline.headIndent - bottomBorderline.tailIndent, + height: bottomBorderline.thick / scale); fromPoint = CGPoint(x: 0, y: 0); toPoint = CGPoint(x: layerRect.size.width, y: 0); } @@ -3922,7 +3952,7 @@ class TGBorderlineLayerDelegate:NSObject,CALayerDelegate retLayer = CAShapeLayer() retLayer.zPosition = 10000 retLayer.delegate = self - _layout.layer.addSublayer(retLayer!) + _layoutLayer.addSublayer(retLayer!) } if borderline.dash != 0 @@ -4043,12 +4073,12 @@ extension UIView var retInt = 0 switch type! { - case .comb(let width, let height, let screen): + case TGSizeClassType.comb(let width, let height, let screen): switch width { - case .compact: + case TGSizeClassType.Width.compact: retInt |= 1 break - case .regular: + case TGSizeClassType.Width.regular: retInt |= 2 break default: @@ -4057,10 +4087,10 @@ extension UIView } switch height { - case .compact: + case TGSizeClassType.Height.compact: retInt |= 4 break - case .regular: + case TGSizeClassType.Height.regular: retInt |= 8 break default: @@ -4069,19 +4099,19 @@ extension UIView if screen != nil { switch screen! { - case .portrait: + case TGSizeClassType.Screen.portrait: retInt |= 64 break - case .landscape: + case TGSizeClassType.Screen.landscape: retInt |= 128 break } } break - case .portrait: + case TGSizeClassType.portrait: retInt = 64 break - case .landscape: + case TGSizeClassType.landscape: retInt = 128 break default: @@ -4095,7 +4125,7 @@ extension UIView fileprivate var tgDefaultSizeClass:TGViewSizeClass { - return tgMatchBestSizeClass(.default) + return tgMatchBestSizeClass(TGSizeClassType.default) } internal func tgMatchBestSizeClass(_ type:TGSizeClassType) ->TGViewSizeClass @@ -4114,12 +4144,12 @@ extension UIView if #available(iOS 8.0, *) { switch type { - case .comb(let width, let height, let screen): + case TGSizeClassType.comb(let width, let height, let screen): switch width { - case .compact: + case TGSizeClassType.Width.compact: wsc = 1 break - case .regular: + case TGSizeClassType.Width.regular: wsc = 2 break default: @@ -4127,10 +4157,10 @@ extension UIView } switch height { - case .compact: + case TGSizeClassType.Height.compact: hsc = 4 break - case .regular: + case TGSizeClassType.Height.regular: hsc = 8 break default: @@ -4139,19 +4169,19 @@ extension UIView if screen != nil { switch screen! { - case .portrait: + case TGSizeClassType.Screen.portrait: ori = 64 break - case .landscape: + case TGSizeClassType.Screen.landscape: ori = 128 break } } break - case .portrait: + case TGSizeClassType.portrait: ori = 64 break - case .landscape: + case TGSizeClassType.landscape: ori = 128 break default: diff --git a/TangramKit/TGFloatLayout.swift b/TangramKit/TGFloatLayout.swift index 4a05520..6e3e989 100644 --- a/TangramKit/TGFloatLayout.swift +++ b/TangramKit/TGFloatLayout.swift @@ -114,12 +114,12 @@ open class TGFloatLayout: TGBaseLayout,TGFloatLayoutViewSizeClass { } */ - public convenience init(_ orientation:TGOrientation = .vert) + public convenience init(_ orientation:TGOrientation = TGOrientation.vert) { - self.init(frame:.zero, orientation:orientation) + self.init(frame:CGRect.zero, orientation:orientation) } - public init(frame: CGRect, orientation:TGOrientation = .vert) { + public init(frame: CGRect, orientation:TGOrientation = TGOrientation.vert) { super.init(frame: frame) @@ -186,7 +186,7 @@ open class TGFloatLayout: TGBaseLayout,TGFloatLayoutViewSizeClass { 2.如果您的布局方向是MyLayoutViewOrientation_Horz表示设置的是子视图的垂直间距,其中的subviewSize指定的是子视图的高度,minSpace指定的是最小的垂直间距,maxSpace指定的是最大的垂直间距,如果指定的subviewSize计算出的间距大于这个值则会调整subviewSize的高度。 3.如果您不想使用浮动间距则请将subviewSize设置为0就可以了。 */ - public func tg_setSubviews(size:CGFloat, minSpace:CGFloat, maxSpace:CGFloat = .greatestFiniteMagnitude, inSizeClass type:TGSizeClassType = .default) + public func tg_setSubviews(size:CGFloat, minSpace:CGFloat, maxSpace:CGFloat = CGFloat.greatestFiniteMagnitude, inSizeClass type:TGSizeClassType = TGSizeClassType.default) { let lsc = self.tg_fetchSizeClass(with: type) as! TGFloatLayoutViewSizeClassImpl lsc.subviewSize = size @@ -241,7 +241,7 @@ open class TGFloatLayout: TGBaseLayout,TGFloatLayoutViewSizeClass { } - if (lsc.tg_orientation == .vert) + if (lsc.tg_orientation == TGOrientation.vert) { selfSize = self.tgLayoutSubviewsForVert(selfSize,sbs:sbs, isEstimate:isEstimate, lsc:lsc); } diff --git a/TangramKit/TGFlowLayout.swift b/TangramKit/TGFlowLayout.swift index 1d95302..c96fffa 100644 --- a/TangramKit/TGFlowLayout.swift +++ b/TangramKit/TGFlowLayout.swift @@ -85,12 +85,12 @@ open class TGFlowLayout:TGBaseLayout,TGFlowLayoutViewSizeClass { /** *初始化一个流式布局并指定布局的方向和布局的数量,如果数量为0则表示内容约束流式布局 */ - public convenience init(_ orientation:TGOrientation = .vert, arrangedCount:Int = 0) { - self.init(frame:.zero, orientation:orientation, arrangedCount:arrangedCount) + public convenience init(_ orientation:TGOrientation = TGOrientation.vert, arrangedCount:Int = 0) { + self.init(frame:CGRect.zero, orientation:orientation, arrangedCount:arrangedCount) } - public init(frame: CGRect, orientation:TGOrientation = .vert, arrangedCount:Int = 0) { + public init(frame: CGRect, orientation:TGOrientation = TGOrientation.vert, arrangedCount:Int = 0) { super.init(frame:frame) let lsc = self.tgCurrentSizeClass as! TGFlowLayoutViewSizeClass @@ -247,7 +247,7 @@ open class TGFlowLayout:TGBaseLayout,TGFlowLayoutViewSizeClass { 3.如果您不想使用浮动间距则请将subviewSize设置为0就可以了。 4.这个方法只在内容约束流式布局里面设置才有意义。 */ - public func tg_setSubviews(size:CGFloat, minSpace:CGFloat, maxSpace:CGFloat = .greatestFiniteMagnitude, inSizeClass type:TGSizeClassType = .default) + public func tg_setSubviews(size:CGFloat, minSpace:CGFloat, maxSpace:CGFloat = CGFloat.greatestFiniteMagnitude, inSizeClass type:TGSizeClassType = TGSizeClassType.default) { let lsc = self.tg_fetchSizeClass(with: type) as! TGFlowLayoutViewSizeClassImpl lsc.subviewSize = size @@ -288,8 +288,8 @@ open class TGFlowLayout:TGBaseLayout,TGFlowLayoutViewSizeClass { { if sbvsc.width.isWrap { - if (lsc.tg_pagedCount > 0 || (lsc.tg_orientation == .horz && (lsc.tg_arrangedGravity & TGGravity.vert.mask) == TGGravity.horz.fill) || - (lsc.tg_orientation == .vert && ((lsc.tg_gravity & TGGravity.vert.mask) == TGGravity.horz.fill))) + if (lsc.tg_pagedCount > 0 || (lsc.tg_orientation == TGOrientation.horz && (lsc.tg_arrangedGravity & TGGravity.vert.mask) == TGGravity.horz.fill) || + (lsc.tg_orientation == TGOrientation.vert && ((lsc.tg_gravity & TGGravity.vert.mask) == TGGravity.horz.fill))) { sbvsc.width.resetValue() } @@ -297,8 +297,8 @@ open class TGFlowLayout:TGBaseLayout,TGFlowLayoutViewSizeClass { if sbvsc.height.isWrap { - if (lsc.tg_pagedCount > 0 || (lsc.tg_orientation == .vert && (lsc.tg_arrangedGravity & TGGravity.horz.mask) == TGGravity.vert.fill) || - (lsc.tg_orientation == .horz && ((lsc.tg_gravity & TGGravity.horz.mask) == TGGravity.vert.fill))) + if (lsc.tg_pagedCount > 0 || (lsc.tg_orientation == TGOrientation.vert && (lsc.tg_arrangedGravity & TGGravity.horz.mask) == TGGravity.vert.fill) || + (lsc.tg_orientation == TGOrientation.horz && ((lsc.tg_gravity & TGGravity.horz.mask) == TGGravity.vert.fill))) { sbvsc.height.resetValue() } @@ -320,7 +320,7 @@ open class TGFlowLayout:TGBaseLayout,TGFlowLayoutViewSizeClass { } } - if lsc.tg_orientation == .vert { + if lsc.tg_orientation == TGOrientation.vert { if lsc.tg_arrangedCount == 0 { @@ -632,7 +632,7 @@ extension TGFlowLayout //为子视图设置单独的对齐方式 let sbvVertAlignment = sbvsc.tg_alignment & TGGravity.horz.mask var vertAlignment = vertAlignment - if sbvVertAlignment != .none + if sbvVertAlignment != TGGravity.none { vertAlignment = sbvVertAlignment } @@ -761,7 +761,7 @@ extension TGFlowLayout //为子视图设置单独的对齐方式 let sbvHorzAlignment = self.tgConvertLeftRightGravityToLeadingTrailing(sbvsc.tg_alignment & TGGravity.vert.mask) var horzAlignment = horzAlignment - if sbvHorzAlignment != .none + if sbvHorzAlignment != TGGravity.none { horzAlignment = sbvHorzAlignment } diff --git a/TangramKit/TGLayoutPos.swift b/TangramKit/TGLayoutPos.swift index da964cc..c45de60 100644 --- a/TangramKit/TGLayoutPos.swift +++ b/TangramKit/TGLayoutPos.swift @@ -342,9 +342,9 @@ final public class TGLayoutPos:TGLayoutPosValue } switch _val! { - case .floatV(let v): + case ValueType.floatV(let v): return v - case .layoutSupport(let v): + case ValueType.layoutSupport(let v): //只有在11以后并且是设置了safearea缩进才忽略UILayoutSupport。 if let superlayout = self.view.superview as? TGBaseLayout, #available(iOS 11.0, *) { @@ -356,7 +356,7 @@ final public class TGLayoutPos:TGLayoutPosValue } } return v.length - case .safePosV(_): + case ValueType.safePosV(_): if #available(iOS 11.0, *) { if let superView = _view.superview @@ -407,7 +407,7 @@ final public class TGLayoutPos:TGLayoutPosValue } switch _val! { - case .weightV(let v): + case ValueType.weightV(let v): return v default: return nil @@ -424,7 +424,7 @@ final public class TGLayoutPos:TGLayoutPosValue } switch _val! { - case .posV(let v): + case ValueType.posV(let v): return v default: return nil @@ -441,7 +441,7 @@ final public class TGLayoutPos:TGLayoutPosValue } switch _val! { - case .arrayV(let v): + case ValueType.arrayV(let v): return v default: return nil @@ -523,28 +523,28 @@ extension TGLayoutPos { if v == TGLayoutPos.tg_safeAreaMargin { - _val = .safePosV(v) + _val = ValueType.safePosV(v) } else { - _val = .floatV(v) + _val = ValueType.floatV(v) } } else if let v = val as? Double { - _val = .floatV(CGFloat(v)) + _val = ValueType.floatV(CGFloat(v)) } else if let v = val as? Float { - _val = .floatV(CGFloat(v)) + _val = ValueType.floatV(CGFloat(v)) } else if let v = val as? Int { - _val = .floatV(CGFloat(v)) + _val = ValueType.floatV(CGFloat(v)) } else if let v = val as? TGWeight { - _val = .weightV(v) + _val = ValueType.weightV(v) } else if let v = val as? [TGLayoutPos] { @@ -553,7 +553,7 @@ extension TGLayoutPos assert(false, "oops! "); } - _val = .arrayV(v) + _val = ValueType.arrayV(v) } else if let v = val as? UIView { @@ -564,22 +564,22 @@ extension TGLayoutPos switch _type { case TGGravity.vert.top: - _val = .posV(v.tg_top) + _val = ValueType.posV(v.tg_top) break case TGGravity.vert.center: - _val = .posV(v.tg_centerY) + _val = ValueType.posV(v.tg_centerY) break case TGGravity.vert.bottom: - _val = .posV(v.tg_bottom) + _val = ValueType.posV(v.tg_bottom) break case TGGravity.horz.leading: - _val = .posV(v.tg_leading) + _val = ValueType.posV(v.tg_leading) break case TGGravity.horz.center: - _val = .posV(v.tg_centerX) + _val = ValueType.posV(v.tg_centerX) break case TGGravity.horz.trailing: - _val = .posV(v.tg_trailing) + _val = ValueType.posV(v.tg_trailing) break default: assert(false, "oops!"); @@ -592,7 +592,7 @@ extension TGLayoutPos assert(false, "oops!") } - _val = .posV(v) + _val = ValueType.posV(v) } else if val == nil @@ -620,7 +620,7 @@ extension TGLayoutPos } _offset = offset - _val = .layoutSupport(val) + _val = ValueType.layoutSupport(val) setNeedsLayout() @@ -684,9 +684,9 @@ extension TGLayoutPos } switch _val! { - case .safePosV(_): + case ValueType.safePosV(_): return true - case .layoutSupport(_): + case ValueType.layoutSupport(_): return true default: return false diff --git a/TangramKit/TGLayoutSize.swift b/TangramKit/TGLayoutSize.swift index 1f45c80..344733b 100644 --- a/TangramKit/TGLayoutSize.swift +++ b/TangramKit/TGLayoutSize.swift @@ -87,11 +87,11 @@ final public class TGLayoutSize:TGLayoutSizeValue //定义三个特殊类型的值。 /// 视图的尺寸由内容或者子视图包裹。 - public static let wrap = TGLayoutSize(.none, view: nil) + public static let wrap = TGLayoutSize(TGGravity.none, view: nil) /// 视图的尺寸填充父视图的剩余空间。 - public static let fill = TGLayoutSize(.none, view: nil) + public static let fill = TGLayoutSize(TGGravity.none, view: nil) /// 视图的尺寸会平分父视图的剩余空间。 - public static let average = TGLayoutSize(.none, view:nil) + public static let average = TGLayoutSize(TGGravity.none, view:nil) //设置尺寸值为一个具体的数值。 @discardableResult @@ -332,7 +332,7 @@ final public class TGLayoutSize:TGLayoutSizeValue } switch _val! { - case .wrapV: + case ValueType.wrapV: return true default: return false @@ -348,7 +348,7 @@ final public class TGLayoutSize:TGLayoutSizeValue } switch _val! { - case .fillV: + case ValueType.fillV: return true default: return false @@ -366,7 +366,7 @@ final public class TGLayoutSize:TGLayoutSizeValue switch _val! { - case .floatV(let v): + case ValueType.floatV(let v): return v default: return nil @@ -383,7 +383,7 @@ final public class TGLayoutSize:TGLayoutSizeValue switch _val! { - case .dimeV(let v): + case ValueType.dimeV(let v): return v default: return nil @@ -403,7 +403,7 @@ final public class TGLayoutSize:TGLayoutSizeValue switch _val! { - case .arrayV(let v): + case ValueType.arrayV(let v): return v default: return nil @@ -420,7 +420,7 @@ final public class TGLayoutSize:TGLayoutSizeValue switch _val! { - case .weightV(let v): + case ValueType.weightV(let v): return v default: return nil @@ -515,27 +515,27 @@ extension TGLayoutSize if let v = val as? CGFloat { - _val = .floatV(v) + _val = ValueType.floatV(v) } else if let v = val as? Double { - _val = .floatV(CGFloat(v)) + _val = ValueType.floatV(CGFloat(v)) } else if let v = val as? Float { - _val = .floatV(CGFloat(v)) + _val = ValueType.floatV(CGFloat(v)) } else if let v = val as? Int { - _val = .floatV(CGFloat(v)) + _val = ValueType.floatV(CGFloat(v)) } else if let v = val as? TGWeight { - _val = .weightV(v) + _val = ValueType.weightV(v) } else if let v = val as? [TGLayoutSize] { - _val = .arrayV(v) + _val = ValueType.arrayV(v) } else if let v = val as? UIView { @@ -546,10 +546,10 @@ extension TGLayoutSize switch _type { case TGGravity.vert.fill: - _val = .dimeV(v.tg_height) + _val = ValueType.dimeV(v.tg_height) break case TGGravity.horz.fill: - _val = .dimeV(v.tg_width) + _val = ValueType.dimeV(v.tg_width) break default: assert(false, "oops!") @@ -565,7 +565,7 @@ extension TGLayoutSize if v === TGLayoutSize.wrap { - _val = .wrapV + _val = ValueType.wrapV if let labelView = _view as? UILabel, _type == TGGravity.vert.fill { @@ -582,15 +582,15 @@ extension TGLayoutSize } else if v === TGLayoutSize.fill { - _val = .fillV + _val = ValueType.fillV } else if v === TGLayoutSize.average { - _val = .weightV(TGWeight(100)) + _val = ValueType.weightV(TGWeight(100)) } else { - _val = .dimeV(v) + _val = ValueType.dimeV(v) } } else if val == nil @@ -666,7 +666,7 @@ extension TGLayoutSize } switch t { - case .floatV(let v): + case ValueType.floatV(let v): return v * _multiple + _increment default: return size @@ -680,7 +680,7 @@ extension TGLayoutSize } switch t { - case .fillV: + case ValueType.fillV: return containerSize * _multiple + _increment default: return size @@ -695,7 +695,7 @@ extension TGLayoutSize } switch t { - case .weightV(let v): + case ValueType.weightV(let v): return (containerSize * v.rawValue / 100) * _multiple + _increment default: return size diff --git a/TangramKit/TGLayoutSizeClass.swift b/TangramKit/TGLayoutSizeClass.swift index 581691a..030528e 100644 --- a/TangramKit/TGLayoutSizeClass.swift +++ b/TangramKit/TGLayoutSizeClass.swift @@ -364,8 +364,8 @@ internal class TGViewSizeClassImpl:NSCopying,TGViewSizeClass { var tg_reverseFloat:Bool = false var tg_clearFloat:Bool = false - var tg_visibility: TGVisibility = .visible - var tg_alignment: TGGravity = .none + var tg_visibility: TGVisibility = TGVisibility.visible + var tg_alignment: TGGravity = TGGravity.none static var IsRTL:Bool = false @@ -589,7 +589,7 @@ internal class TGLayoutViewSizeClassImpl:TGViewSizeClassImpl,TGLayoutViewSizeCla var tg_zeroPadding: Bool = true - var tg_insetsPaddingFromSafeArea: UIRectEdge = [.left, .right] + var tg_insetsPaddingFromSafeArea: UIRectEdge = [UIRectEdge.left, UIRectEdge.right] var tg_insetLandscapeFringePadding: Bool = false var tg_vspace:CGFloat = 0 @@ -609,7 +609,7 @@ internal class TGLayoutViewSizeClassImpl:TGViewSizeClassImpl,TGLayoutViewSizeCla } var tg_reverseLayout: Bool = false - var tg_gravity: TGGravity = .none + var tg_gravity: TGGravity = TGGravity.none internal var tgTopPadding:CGFloat @@ -657,13 +657,13 @@ internal class TGLayoutViewSizeClassImpl:TGViewSizeClassImpl,TGLayoutViewSizeCla var devori:UIDeviceOrientation if TGViewSizeClassImpl.IsRTL { - edge = .right - devori = .landscapeLeft + edge = UIRectEdge.right + devori = UIDeviceOrientation.landscapeLeft } else { - edge = .left - devori = .landscapeRight + edge = UIRectEdge.left + devori = UIDeviceOrientation.landscapeRight } if (self.tg_insetsPaddingFromSafeArea.rawValue & edge.rawValue) == edge.rawValue @@ -759,13 +759,13 @@ internal class TGLayoutViewSizeClassImpl:TGViewSizeClassImpl,TGLayoutViewSizeCla var devori:UIDeviceOrientation if TGViewSizeClassImpl.IsRTL { - edge = .left - devori = .landscapeRight + edge = UIRectEdge.left + devori = UIDeviceOrientation.landscapeRight } else { - edge = .right - devori = .landscapeLeft + edge = UIRectEdge.right + devori = UIDeviceOrientation.landscapeLeft } if (self.tg_insetsPaddingFromSafeArea.rawValue & edge.rawValue) == edge.rawValue @@ -835,7 +835,7 @@ internal class TGLayoutViewSizeClassImpl:TGViewSizeClassImpl,TGLayoutViewSizeCla internal class TGSequentLayoutViewSizeClassImpl:TGLayoutViewSizeClassImpl,TGSequentLayoutViewSizeClass { - var tg_orientation:TGOrientation = .vert + var tg_orientation:TGOrientation = TGOrientation.vert override func copy(with zone: NSZone?) -> Any { @@ -850,7 +850,7 @@ internal class TGSequentLayoutViewSizeClassImpl:TGLayoutViewSizeClassImpl,TGSequ internal class TGLinearLayoutViewSizeClassImpl:TGSequentLayoutViewSizeClassImpl,TGLinearLayoutViewSizeClass { - var tg_shrinkType: TGSubviewsShrinkType = .none + var tg_shrinkType: TGSubviewsShrinkType = TGSubviewsShrinkType.none override func copy(with zone: NSZone?) -> Any { @@ -875,7 +875,7 @@ internal class TGFloatLayoutViewSizeClassImpl : TGSequentLayoutViewSizeClassImpl var subviewSize:CGFloat = 0 var minSpace:CGFloat = 0 - var maxSpace:CGFloat = .greatestFiniteMagnitude + var maxSpace:CGFloat = CGFloat.greatestFiniteMagnitude override func copy(with zone: NSZone?) -> Any { @@ -897,12 +897,12 @@ internal class TGFlowLayoutViewSizeClassImpl:TGSequentLayoutViewSizeClassImpl,TG { var tg_arrangedCount:Int = 0 var tg_pagedCount:Int = 0 - var tg_arrangedGravity:TGGravity = .none + var tg_arrangedGravity:TGGravity = TGGravity.none var tg_autoArrange:Bool = false var subviewSize:CGFloat = 0 var minSpace:CGFloat = 0 - var maxSpace:CGFloat = .greatestFiniteMagnitude + var maxSpace:CGFloat = CGFloat.greatestFiniteMagnitude override func copy(with zone: NSZone?) -> Any { diff --git a/TangramKit/TGLinearLayout.swift b/TangramKit/TGLinearLayout.swift index e5aa316..f45e210 100644 --- a/TangramKit/TGLinearLayout.swift +++ b/TangramKit/TGLinearLayout.swift @@ -43,7 +43,7 @@ open class TGLinearLayout: TGBaseLayout,TGLinearLayoutViewSizeClass { public convenience init(_ orientation:TGOrientation) { - self.init(frame:.zero, orientation:orientation) + self.init(frame:CGRect.zero, orientation:orientation) } @@ -172,10 +172,10 @@ open class TGLinearLayout: TGBaseLayout,TGLinearLayoutViewSizeClass { *@space参数指定子视图之间的固定间距。 *@type参数表示设置在指定sizeClass下进行子视图和间距的均分 */ - public func tg_equalizeSubviews(centered:Bool, withSpace space:CGFloat! = nil, inSizeClass type:TGSizeClassType = .default) + public func tg_equalizeSubviews(centered:Bool, withSpace space:CGFloat! = nil, inSizeClass type:TGSizeClassType = TGSizeClassType.default) { switch type { - case .default: + case TGSizeClassType.default: break default: self.tgFrame.sizeClass = self.tg_fetchSizeClass(with:type) @@ -185,7 +185,7 @@ open class TGLinearLayout: TGBaseLayout,TGLinearLayoutViewSizeClass { } } - if self.tg_orientation == .vert + if self.tg_orientation == TGOrientation.vert { tgEqualizeSubviewsForVert(centered, withSpace: space) } @@ -196,14 +196,14 @@ open class TGLinearLayout: TGBaseLayout,TGLinearLayoutViewSizeClass { } switch type { - case .default: + case TGSizeClassType.default: self.setNeedsLayout() break default: - self.tgFrame.sizeClass = self.tg_fetchSizeClass(with:.default) + self.tgFrame.sizeClass = self.tg_fetchSizeClass(with:TGSizeClassType.default) for sbv:UIView in self.subviews { - sbv.tgFrame.sizeClass = sbv.tg_fetchSizeClass(with:.default) + sbv.tgFrame.sizeClass = sbv.tg_fetchSizeClass(with:TGSizeClassType.default) } } @@ -214,11 +214,11 @@ open class TGLinearLayout: TGBaseLayout,TGLinearLayoutViewSizeClass { *@centered参数意义同上。 *@type参数的意义同上。 */ - public func tg_equalizeSubviewsSpace(centered:Bool, inSizeClass type:TGSizeClassType = .default) + public func tg_equalizeSubviewsSpace(centered:Bool, inSizeClass type:TGSizeClassType = TGSizeClassType.default) { switch type { - case .default: + case TGSizeClassType.default: break default: self.tgFrame.sizeClass = self.tg_fetchSizeClass(with:type) @@ -228,7 +228,7 @@ open class TGLinearLayout: TGBaseLayout,TGLinearLayoutViewSizeClass { } } - if self.tg_orientation == .vert + if self.tg_orientation == TGOrientation.vert { tgEqualizeSubviewsSpaceForVert(centered) } @@ -239,14 +239,14 @@ open class TGLinearLayout: TGBaseLayout,TGLinearLayoutViewSizeClass { switch type { - case .default: + case TGSizeClassType.default: self.setNeedsLayout() break default: - self.tgFrame.sizeClass = self.tg_fetchSizeClass(with:.default) + self.tgFrame.sizeClass = self.tg_fetchSizeClass(with:TGSizeClassType.default) for sbv:UIView in self.subviews { - sbv.tgFrame.sizeClass = sbv.tg_fetchSizeClass(with:.default) + sbv.tgFrame.sizeClass = sbv.tg_fetchSizeClass(with:TGSizeClassType.default) } } } @@ -303,10 +303,10 @@ open class TGLinearLayout: TGBaseLayout,TGLinearLayoutViewSizeClass { } - if lsc.tg_orientation == .vert + if lsc.tg_orientation == TGOrientation.vert { - if vertGravity != .none + if vertGravity != TGGravity.none { selfSize = self.tgLayoutSubviewsForVertGravity(selfSize,sbs:sbs, lsc:lsc) } @@ -317,7 +317,7 @@ open class TGLinearLayout: TGBaseLayout,TGLinearLayoutViewSizeClass { } else { - if horzGravity != .none + if horzGravity != TGGravity.none { selfSize = self.tgLayoutSubviewsForHorzGravity(selfSize,sbs:sbs, lsc:lsc) } @@ -567,7 +567,7 @@ extension TGLinearLayout { { var temp:CGFloat = subviewMeasure; - var tempWeight:TGWeight = .zeroWeight; + var tempWeight:TGWeight = TGWeight.zeroWeight; let hm:CGFloat = headPos.floatNumber let cm:CGFloat = centerPos.floatNumber @@ -649,7 +649,7 @@ extension TGLinearLayout { { var fixedHeight:CGFloat = 0 //计算固定部分的高度 var floatingHeight:CGFloat = 0 //浮动的高度。 - var totalWeight:TGWeight = .zeroWeight //剩余部分的总比重 + var totalWeight:TGWeight = TGWeight.zeroWeight //剩余部分的总比重 var selfSize = selfSize let horzGravity = self.tgConvertLeftRightGravityToLeadingTrailing(lsc.tg_gravity & TGGravity.vert.mask) let topPadding = lsc.tgTopPadding @@ -775,7 +775,7 @@ extension TGLinearLayout { //在包裹宽度且总体比重不为0时则,则需要还原最小的宽度,这样就不会使得宽度在横竖屏或者多次计算后越来越宽。 - if lsc.height.isWrap && totalWeight != .zeroWeight + if lsc.height.isWrap && totalWeight != TGWeight.zeroWeight { var tempSelfHeight = topPadding + bottomPadding if sbs.count > 1 @@ -796,14 +796,14 @@ extension TGLinearLayout { let sstContent:TGSubviewsShrinkType = TGSubviewsShrinkType(rawValue: lsc.tg_shrinkType.rawValue & 0xF0) //压缩内容 if _tgCGFloatLessOrEqual(floatingHeight, 0) { - if sstMode != .none + if sstMode != TGSubviewsShrinkType.none { - if sstContent != .space + if sstContent != TGSubviewsShrinkType.space { - if (fixedSizeSbs.count > 0 && totalWeight != .zeroWeight && floatingHeight < 0 && selfSize.height > 0) + if (fixedSizeSbs.count > 0 && totalWeight != TGWeight.zeroWeight && floatingHeight < 0 && selfSize.height > 0) { - if sstMode == .average + if sstMode == TGSubviewsShrinkType.average { let averageHeight = floatingHeight / CGFloat(fixedSizeSbs.count); for fsbv in fixedSizeSbs @@ -828,11 +828,11 @@ extension TGLinearLayout { { if (fixedSpaceCount > 0 && floatingHeight < 0 && selfSize.height > 0 && fixedSpaceHeight > 0) { - if (sstMode == .average) + if (sstMode == TGSubviewsShrinkType.average) { addSpace = floatingHeight / CGFloat(fixedSpaceCount) } - else if (sstMode == .weight) + else if (sstMode == TGSubviewsShrinkType.weight) { isWeightShrinkSpace = true weightShrinkSpaceTotalHeight = floatingHeight; @@ -849,7 +849,7 @@ extension TGLinearLayout { floatingHeight = 0; } - if totalWeight != .zeroWeight || (sstMode != .none && _tgCGFloatLessOrEqual(floatingHeight, 0)) + if totalWeight != TGWeight.zeroWeight || (sstMode != TGSubviewsShrinkType.none && _tgCGFloatLessOrEqual(floatingHeight, 0)) { pos = topPadding for sbv in sbs @@ -989,7 +989,7 @@ extension TGLinearLayout { let vertGravity = lsc.tg_gravity & TGGravity.horz.mask var fixedWidth:CGFloat = 0; //计算固定部分的高度 var floatingWidth:CGFloat = 0; //浮动的高度。 - var totalWeight:TGWeight = .zeroWeight + var totalWeight:TGWeight = TGWeight.zeroWeight let topPadding = lsc.tgTopPadding let bottomPadding = lsc.tgBottomPadding let leadingPadding = lsc.tgLeadingPadding @@ -1116,19 +1116,19 @@ extension TGLinearLayout { let sstContent:TGSubviewsShrinkType = TGSubviewsShrinkType(rawValue: lsc.tg_shrinkType.rawValue & 0xF0) //压缩内容 - if sstMode == .auto && flexedSizeSbs.count != 2 + if sstMode == TGSubviewsShrinkType.auto && flexedSizeSbs.count != 2 { - sstMode = .none + sstMode = TGSubviewsShrinkType.none } - if sstMode != .none + if sstMode != TGSubviewsShrinkType.none { - if sstContent != .space + if sstContent != TGSubviewsShrinkType.space { - if (fixedSizeSbs.count > 0 && totalWeight != .zeroWeight && floatingWidth < 0 && selfSize.width > 0) + if (fixedSizeSbs.count > 0 && totalWeight != TGWeight.zeroWeight && floatingWidth < 0 && selfSize.width > 0) { - if sstMode == .average + if sstMode == TGSubviewsShrinkType.average { let averageWidth = floatingWidth / CGFloat(fixedSizeSbs.count) for fsbv in fixedSizeSbs @@ -1136,7 +1136,7 @@ extension TGLinearLayout { fsbv.tgFrame.width += averageWidth; } } - else if sstMode == .auto + else if sstMode == TGSubviewsShrinkType.auto { let leftView = flexedSizeSbs[0] let rightView = flexedSizeSbs[1] @@ -1193,11 +1193,11 @@ extension TGLinearLayout { { if (fixedSpaceCount > 0 && floatingWidth < 0 && selfSize.height > 0 && fixedSpaceWidth > 0) { - if (sstMode == .average) + if (sstMode == TGSubviewsShrinkType.average) { addSpace = floatingWidth / CGFloat(fixedSpaceCount) } - else if (sstMode == .weight) + else if (sstMode == TGSubviewsShrinkType.weight) { isWeightShrinkSpace = true weightShrinkSpaceTotalWidth = floatingWidth @@ -1827,7 +1827,7 @@ extension TGLinearLayout { fileprivate func tgAdjustSubviewWrapContent(sbvsc:TGViewSizeClassImpl, lsc:TGLinearLayoutViewSizeClassImpl) { - if lsc.tg_orientation == .vert + if lsc.tg_orientation == TGOrientation.vert { if (sbvsc.isHorzMarginHasValue) || @@ -1916,7 +1916,7 @@ extension TGLinearLayout { } var subviewSpace = lsc.tg_vspace - if lsc.tg_orientation == .horz + if lsc.tg_orientation == TGOrientation.horz { subviewSpace = lsc.tg_hspace } @@ -1928,7 +1928,7 @@ extension TGLinearLayout { { if !sbvl.tg_notUseIntelligentBorderline { - if lsc.tg_orientation == .vert + if lsc.tg_orientation == TGOrientation.vert { sbvl.tg_topBorderline = nil; sbvl.tg_bottomBorderline = nil; @@ -1966,7 +1966,7 @@ extension TGLinearLayout { if (ok) { - if lsc.tg_orientation == .vert + if lsc.tg_orientation == TGOrientation.vert { sbvl.tg_topBorderline = self.tg_intelligentBorderline } @@ -1980,7 +1980,7 @@ extension TGLinearLayout { if nextSiblingView != nil && ((nextSiblingView as? TGBaseLayout) == nil || subviewSpace != 0) { - if lsc.tg_orientation == .vert + if lsc.tg_orientation == TGOrientation.vert { sbvl.tg_bottomBorderline = self.tg_intelligentBorderline; } diff --git a/TangramKit/TGPathLayout.swift b/TangramKit/TGPathLayout.swift index 3324a22..d8d012d 100644 --- a/TangramKit/TGPathLayout.swift +++ b/TangramKit/TGPathLayout.swift @@ -27,11 +27,11 @@ public enum TGPathSpaceType{ extension TGPathSpaceType : Equatable{ public static func ==(lhs: TGPathSpaceType, rhs: TGPathSpaceType) -> Bool { switch (lhs,rhs) { - case ( .flexed , .flexed): + case ( TGPathSpaceType.flexed , TGPathSpaceType.flexed): return true - case (let .fixed(value1),let .fixed(value2)): + case (let TGPathSpaceType.fixed(value1),let TGPathSpaceType.fixed(value2)): return value1 == value2 - case (let .count(count1),let .count(count2)): + case (let TGPathSpaceType.count(count1),let TGPathSpaceType.count(count2)): return count1 == count2 default: return false @@ -49,7 +49,7 @@ open class TGCoordinateSetting { /** * 坐标原点的位置,位置是相对位置,默认是(0,0), 假如设置为(0.5,0.5)则在视图的中间。 */ - public var origin : CGPoint = .zero { + public var origin : CGPoint = CGPoint.zero { didSet{ if !_tgCGPointEqual(oldValue, origin){ @@ -185,7 +185,7 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass { /** * 设置子视图在路径曲线上的距离的类型,一共有flexed, fixed, count,默认是flexed, */ - public var tg_spaceType : TGPathSpaceType = .flexed { + public var tg_spaceType : TGPathSpaceType = TGPathSpaceType.flexed { didSet{ if tg_spaceType != oldValue { setNeedsLayout() @@ -611,22 +611,22 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass { sbv.tgFrame.frame = rect } - if minYPos == .greatestFiniteMagnitude + if minYPos == CGFloat.greatestFiniteMagnitude { minYPos = 0 } - if maxYPos == -.greatestFiniteMagnitude + if maxYPos == -CGFloat.greatestFiniteMagnitude { maxYPos = lsc.tgTopPadding + lsc.tgBottomPadding } - if minXPos == .greatestFiniteMagnitude + if minXPos == CGFloat.greatestFiniteMagnitude { minXPos = 0 } - if maxXPos == -.greatestFiniteMagnitude + if maxXPos == -CGFloat.greatestFiniteMagnitude { maxXPos = lsc.tgLeftPadding + lsc.tgRightPadding } @@ -670,9 +670,9 @@ extension TGPathLayout{ var pathLen : CGFloat? = nil var sbvcount = sbs.count switch tg_spaceType { - case let .fixed(value): + case let TGPathSpaceType.fixed(value): return tgCalcPathPoints(showPath: path, pPathLen: &pathLen, subviewCount: sbs.count, pointIndexArray: &pointIndexArray, viewSpace: value) - case let .count(count): + case let TGPathSpaceType.count(count): sbvcount = count default: break diff --git a/TangramKit/TGRelativeLayout.swift b/TangramKit/TGRelativeLayout.swift index 7155eba..eede451 100644 --- a/TangramKit/TGRelativeLayout.swift +++ b/TangramKit/TGRelativeLayout.swift @@ -15,36 +15,6 @@ import UIKit */ open class TGRelativeLayout: TGBaseLayout,TGRelativeLayoutViewSizeClass { - /** - *这个属性在新版本将失效并且无任何意义了。如果想让子视图隐藏时是否继续占据位置则请参考使用子视图的tg_visibility属性来设置。 - */ - @available(*, deprecated:1.0.6, message: "this property was invalid, please use subview's tg_visibility to instead") - public var tg_autoLayoutViewGroupWidth: Bool { - get { - return false - } - set { - - print("tg_autoLayoutViewGroupWidth is invalid please use subview's tg_visibility to instead") - - } - } - - /** - *这个属性在新版本将失效并且无任何意义了。如果想让子视图隐藏时是否继续占据位置则请参考使用子视图的tg_visibility属性来设置。 - */ - @available(*, deprecated:1.0.6, message: "this property was invalid, please use subview's tg_visibility to instead") - public var tg_autoLayoutViewGroupHeight: Bool { - - get { - return false - } - - set { - print("tg_autoLayoutViewGroupHeight is invalid please use subview's tg_visibility to instead") - - } - } //MARK: override method diff --git a/TangramKit/TGTableLayout.swift b/TangramKit/TGTableLayout.swift index 43d0ede..487084e 100644 --- a/TangramKit/TGTableLayout.swift +++ b/TangramKit/TGTableLayout.swift @@ -50,7 +50,7 @@ open class TGTableLayout: TGLinearLayout { return tg_insertRow(size: rowSize, colSize:colSize, rowIndex: self.tg_rowCount) } - public func tg_addRow(size rowSize:TGTableRowColSizeType, colCount:UInt) ->TGLinearLayout + public func tg_addRow(size rowSize:TGTableRowColSizeType, colCount:Int) ->TGLinearLayout { return tg_insertRow(size: rowSize, colSize:TGTableLayout._stgColCountTag - CGFloat(colCount), rowIndex: self.tg_rowCount) } @@ -62,18 +62,18 @@ open class TGTableLayout: TGLinearLayout { public func tg_insertRow(size rowSize: TGTableRowColSizeType, colSize : TGTableRowColSizeType, rowIndex : Int) ->TGLinearLayout { let lsc = self.tgCurrentSizeClass as! TGTableLayoutViewSizeClass - var ori:TGOrientation = .vert; - if (lsc.tg_orientation == .vert) + var ori:TGOrientation = TGOrientation.vert + if (lsc.tg_orientation == TGOrientation.vert) { - ori = .horz; + ori = TGOrientation.horz } else { - ori = .vert; + ori = TGOrientation.vert } let rowView = TGTableRowLayout(orientation: ori, rowSize: rowSize, colSize: colSize) - if ori == .horz + if ori == TGOrientation.horz { rowView.tg_hspace = lsc.tg_hspace } @@ -151,7 +151,7 @@ open class TGTableLayout: TGLinearLayout { { if v === TGLayoutSize.average { - if (rowsc.tg_orientation == .horz) + if (rowsc.tg_orientation == TGOrientation.horz) { colsc.tg_width.equal(v) } @@ -167,7 +167,7 @@ open class TGTableLayout: TGLinearLayout { { let colCount = TGTableLayout._stgColCountTag - v - if rowsc.tg_orientation == .horz + if rowsc.tg_orientation == TGOrientation.horz { colsc.tg_width.equalHelper(val:rowView.tg_width, increment:-1 * rowView.tg_hspace * (colCount - 1.0) / colCount, multiple:1.0 / colCount) } @@ -178,7 +178,7 @@ open class TGTableLayout: TGLinearLayout { } else { - if (rowsc.tg_orientation == .horz) + if (rowsc.tg_orientation == TGOrientation.horz) { colsc.tg_width.equalHelper(val:rowView.colSize) } @@ -189,7 +189,7 @@ open class TGTableLayout: TGLinearLayout { } } - if (rowsc.tg_orientation == .horz) + if (rowsc.tg_orientation == TGOrientation.horz) { if (colView.bounds.size.height == 0 && !colsc.height.hasValue) { @@ -243,8 +243,8 @@ open class TGTableLayout: TGLinearLayout { */ public func tg_exchangeCol(_ indexPath1: IndexPath, with indexPath2: IndexPath) { - let colView1 = self.tg_colView(at:indexPath1); - let colView2 = self.tg_colView(at:indexPath2); + let colView1:UIView = self.tg_colView(at:indexPath1); + let colView2:UIView = self.tg_colView(at:indexPath2); if (colView1 == colView2) { @@ -284,7 +284,7 @@ open class TGTableLayout: TGLinearLayout { } set { super.tg_vspace = newValue - if self.tg_orientation == .horz + if self.tg_orientation == TGOrientation.horz { for i in 0 ..< self.tg_rowCount { @@ -300,7 +300,7 @@ open class TGTableLayout: TGLinearLayout { } set { super.tg_hspace = newValue - if self.tg_orientation == .vert + if self.tg_orientation == TGOrientation.vert { for i in 0 ..< self.tg_rowCount { @@ -385,7 +385,7 @@ private class TGTableRowLayout: TGLinearLayout,TGTableLayoutViewSizeClass { { self.rowSize = rowSize self.colSize = colSize - super.init(frame:.zero, orientation:orientation) + super.init(frame:CGRect.zero, orientation:orientation) let lsc = self.tgCurrentSizeClass as! TGLinearLayoutViewSizeClassImpl @@ -393,7 +393,7 @@ private class TGTableRowLayout: TGLinearLayout,TGTableLayoutViewSizeClass { { if v === TGLayoutSize.average || v === TGLayoutSize.wrap { - if (orientation == .horz) + if (orientation == TGOrientation.horz) { lsc.tg_height.equal(v) } @@ -410,7 +410,7 @@ private class TGTableRowLayout: TGLinearLayout,TGTableLayoutViewSizeClass { } else { - if (orientation == .horz) + if (orientation == TGOrientation.horz) { lsc.tg_height.equalHelper(val:rowSize) } @@ -434,7 +434,7 @@ private class TGTableRowLayout: TGLinearLayout,TGTableLayoutViewSizeClass { if isNoWrap { - if (orientation == .horz) + if (orientation == TGOrientation.horz) { lsc.width.realSize?.equal(nil) lsc.tg_leading.equal(0); @@ -450,13 +450,13 @@ private class TGTableRowLayout: TGLinearLayout,TGTableLayoutViewSizeClass { } else { - if (orientation == .horz) + if (orientation == TGOrientation.horz) { - lsc.tg_width.equal(.wrap) + lsc.tg_width.equal(TGLayoutSize.wrap) } else { - lsc.tg_height.equal(.wrap) + lsc.tg_height.equal(TGLayoutSize.wrap) } } @@ -468,6 +468,32 @@ private class TGTableRowLayout: TGLinearLayout,TGTableLayoutViewSizeClass { super.init(coder:aDecoder) //fatalError("init(coder:) has not been implemented") } + + override internal func tgHook(sublayout:TGBaseLayout, borderlineRect: inout CGRect) + { + /* + 如果行布局是包裹的,那么意味着里面的列子视图都需要自己指定行的尺寸,这样列子视图就会有不同的尺寸,如果是有智能边界线时就会出现每个列子视图的边界线的长度不一致的情况。 + 有时候我们希望列子视图的边界线能够布满整个行(比如垂直表格中,所有列子视图的的高度都和所在行的行高是一致的)因此我们需要将列子视图的边界线的可显示范围进行调整。 + 因此我们重载这个方法来解决这个问题,这个方法可以将列子视图的边界线的区域进行扩充和调整,目的是为了让列子视图的边界线能够布满整个行布局上。 + */ + if let v = rowSize as? TGLayoutSize, v === TGLayoutSize.wrap + { + if self.tg_orientation == TGOrientation.horz + { + //垂直表格下,行是水平的,所以这里需要将列子视图的y轴的位置和行对齐。 + borderlineRect.origin.y = 0 - sublayout.frame.origin.y + //垂直表格下,行是水平的,所以这里需要将子视图的边界线的高度和行的高度保持一致。 + borderlineRect.size.height = self.bounds.size.height + } + else + { + //水平表格下,行是垂直的,所以这里需要将列子视图的x轴的位置和行对齐。 + borderlineRect.origin.x = 0 - sublayout.frame.origin.x + //水平表格下,行是垂直的,所以这里需要将子视图的边界线的宽度和行的宽度保持一致。 + borderlineRect.size.width = self.bounds.size.width + } + } + } } diff --git a/TangramKit/TangramKit.swift b/TangramKit/TangramKit.swift index b023ecd..b0004b1 100644 --- a/TangramKit/TangramKit.swift +++ b/TangramKit/TangramKit.swift @@ -53,7 +53,7 @@ */ -//Current version is 1.1.4, please open: https://github.com/youngsoft/TangramKit/blob/master/CHANGELOG.md to show the changes. +//Current version is 1.1.5, please open: https://github.com/youngsoft/TangramKit/blob/master/CHANGELOG.md to show the changes. diff --git a/TangramKitDemo/Info.plist b/TangramKitDemo/Info.plist index f4b9183..a4faed8 100644 --- a/TangramKitDemo/Info.plist +++ b/TangramKitDemo/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.1.3 + 1.1.5 CFBundleSignature ???? CFBundleVersion diff --git a/TangramKitDemo/Support Files/zh-Hans.lproj/Localizable.strings b/TangramKitDemo/Support Files/zh-Hans.lproj/Localizable.strings index e2da175..26ff406 100644 --- a/TangramKitDemo/Support Files/zh-Hans.lproj/Localizable.strings +++ b/TangramKitDemo/Support Files/zh-Hans.lproj/Localizable.strings @@ -25,6 +25,7 @@ "1.TableLayout - Vert" = "1.表格布局-垂直表格"; "2.TableLayout - Waterfall(Horz)" = "2.表格布局-水平表格实现瀑布流"; "3.TableLayout - Intelligent Borderline" = "3.表格布局-表格和智能边界线"; +"4.TableLayout - Sytle&Alignment" = "4.表格布局-样式和对齐"; "1.FlowLayout - Regular arrangement" = "1.流式布局-有规律的子视图排列"; "2.FlowLayout - Tag cloud" = "2.流式布局-标签流"; "3.FlowLayout - Drag" = "3.流式布局-子视图的拖拽调整功能"; diff --git a/TangramKitDemo/TableLayoutDemo/TLTest4ViewController.swift b/TangramKitDemo/TableLayoutDemo/TLTest4ViewController.swift new file mode 100644 index 0000000..bb94962 --- /dev/null +++ b/TangramKitDemo/TableLayoutDemo/TLTest4ViewController.swift @@ -0,0 +1,160 @@ +// +// TLTest4ViewController.swift +// TangramKit +// +// Created by apple on 16/7/18. +// Copyright © 2016年 youngsoft. All rights reserved. +// + +import UIKit + + + +class TLTest4ViewController: UIViewController { + + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + override func loadView() { + + /* + 这个例子是将表格布局和智能边界线的应用结合,实现一个表格界面。 + + */ + + let scrollView = UIScrollView() + scrollView.backgroundColor = .white + scrollView.contentInset = UIEdgeInsetsMake(0, 0, 10, 0) + self.view = scrollView + + + if #available(iOS 11.0, *) { + } else { + // Fallback on earlier versions + + self.edgesForExtendedLayout = UIRectEdge(rawValue:0) + + } + + + let tableLayout = TGTableLayout(.vert) + tableLayout.tg_height.equal(.wrap) + //这里设置表格的左边和右边以及顶部的边距都是在父视图的安全区域外再缩进10个点的位置。你会注意到这里面定义了一个特殊的位置TGLayoutPos.tg_safeAreaMargin。 + //TGLayoutPos.tg_safeAreaMargin表示视图的边距不是一个固定的值而是所在的父视图的安全区域。这样布局视图就不会延伸到安全区域以外去了。 + //TGLayoutPos.tg_safeAreaMargin是同时支持iOS11和以下的版本的,对于iOS11以下的版本则顶部安全区域是状态栏以下的位置。 + //因此只要你设置边距为MyLayoutPos.safeAreaMargin则可以同时兼容所有iOS的版本。。 + tableLayout.tg_leading.equal(TGLayoutPos.tg_safeAreaMargin, offset: 10) + tableLayout.tg_trailing.equal(TGLayoutPos.tg_safeAreaMargin, offset: 10) + tableLayout.tg_top.equal(TGLayoutPos.tg_safeAreaMargin, offset: 10) + scrollView.addSubview(tableLayout) + + //建立一个表格外边界的边界线。颜色为黑色,粗细为3. + tableLayout.tg_boundBorderline = TGBorderline(color:CFTool.color(4), thick: 3) + //建立智能边界线。所谓智能边界线就是布局里面的如果有子布局视图,则子布局视图会根据自身的布局位置智能的设置边界线。 + //智能边界线只支持表格布局、线性布局、流式布局、浮动布局。 + //如果要想完美使用智能分界线,则请将cellview建立为一个布局视图。 + tableLayout.tg_intelligentBorderline = TGBorderline(color:CFTool.color(5)) + + + let titles = ["身高(Height)(cm)", "体重(Weight)(kg)", "胸围(Bust)(cm)","腰围(Waist)(cm)","臀围(Hip)(cm)","鞋码(Shoes Size)(欧码)"] + let values = ["177","54","88","88","88","43"] + + //第一行 + let row1 = tableLayout.tg_addRow(size:TGLayoutSize.wrap, colCount:titles.count) + row1.tg_gravity = TGGravity.vert.top + row1.backgroundColor = CFTool.color(8) + titles.forEach({tableLayout.addSubview(self.itemFrom(text: $0, alignment: .center)) }) + + + + //第二行 + let row2 = tableLayout.tg_addRow(size:TGLayoutSize.wrap, colCount:titles.count) + row2.tg_gravity = TGGravity.vert.center + titles.forEach({tableLayout.addSubview(self.itemFrom(text: $0, alignment: .center)) }) + + + //第三行 + let row3 = tableLayout.tg_addRow(size:TGLayoutSize.wrap, colCount:titles.count) + row3.tg_gravity = TGGravity.vert.bottom + titles.forEach({tableLayout.addSubview(self.itemFrom(text: $0, alignment: .center)) }) + + + //第四行 + _ = tableLayout.tg_addRow(size:50, colCount:titles.count) + titles.forEach({tableLayout.addSubview(self.itemFrom(text: $0, alignment: .center, isFitWidth:true)) }) + + + //第五行 + _ = tableLayout.tg_addRow(size:TGLayoutSize.wrap, colCount:values.count) + values.forEach({tableLayout.addSubview(self.itemFrom(text: $0, alignment: .left)) }) + + + //第六行 + _ = tableLayout.tg_addRow(size:TGLayoutSize.wrap, colCount:values.count) + values.forEach({tableLayout.addSubview(self.itemFrom(text: $0, alignment: .center)) }) + + + //第7行 + _ = tableLayout.tg_addRow(size:TGLayoutSize.wrap, colCount:values.count) + values.forEach({tableLayout.addSubview(self.itemFrom(text: $0, alignment: .right)) }) + + + } + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) { + // Get the new view controller using segue.destinationViewController. + // Pass the selected object to the new view controller. + } + */ + +} + +extension TLTest4ViewController +{ + + func itemFrom(text:String, alignment:NSTextAlignment, isFitWidth:Bool = false) -> TGBaseLayout + { + let itemLayout = TGFrameLayout() + itemLayout.tg_topPadding = 10 + itemLayout.tg_bottomPadding = 10 + itemLayout.tg_leadingPadding = 10 + itemLayout.tg_trailingPadding = 5 + + let label = UILabel() + label.text = text + label.textAlignment = alignment + label.textColor = CFTool.color(4) + itemLayout.addSubview(label) + + if isFitWidth + { + itemLayout.tg_gravity = TGGravity.fill + label.adjustsFontSizeToFitWidth = true + label.numberOfLines = 0 + } + else + { + itemLayout.tg_gravity = TGGravity.horz.fill + itemLayout.tg_height.equal(.wrap) + label.tg_height.equal(.wrap) + } + + + return itemLayout + } + + +} diff --git a/TangramKitDemo/ViewController.swift b/TangramKitDemo/ViewController.swift index 791b9e2..6a786c3 100644 --- a/TangramKitDemo/ViewController.swift +++ b/TangramKitDemo/ViewController.swift @@ -100,6 +100,9 @@ class ViewController: UITableViewController { demoVCList4.append(["title":NSLocalizedString("3.TableLayout - Intelligent Borderline",comment:""), "class":TLTest3ViewController.self] ) + demoVCList4.append(["title":NSLocalizedString("4.TableLayout - Sytle&Alignment",comment:""), + "class":TLTest4ViewController.self] + ) //flow layout list