From e002e3dfb28d32c2e2c4ca20c404381a75e04b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A7=E6=9F=8F=E6=B3=89?= Date: Sat, 23 Sep 2017 11:59:52 +0800 Subject: [PATCH] Release v1.1.2 and support iOS11 and support iPhoneX --- CHANGELOG.md | 24 ++ README.md | 2 +- README.zh.md | 2 +- TangramKit.podspec | 49 +--- TangramKit.xcodeproj/project.pbxproj | 37 +-- TangramKit/Info.plist | 2 +- TangramKit/TGBaseLayout.swift | 124 ++++++++--- TangramKit/TGFloatLayout.swift | 142 ++++++------ TangramKit/TGFlowLayout.swift | 210 +++++++++--------- TangramKit/TGFrameLayout.swift | 22 +- TangramKit/TGLayoutPos.swift | 12 +- TangramKit/TGLayoutSize.swift | 2 +- TangramKit/TGLayoutSizeClass.swift | 187 +++++++++++++++- TangramKit/TGLinearLayout.swift | 114 ++++++---- TangramKit/TGPathLayout.swift | 49 ++-- TangramKit/TGRelativeLayout.swift | 98 ++++---- TangramKit/TGTableLayout.swift | 62 +++++- TangramKit/TangramKit.swift | 7 +- TangramKitDemo/AppDelegate.swift | 3 + .../FOLTest1ViewController.swift | 8 +- .../FOLTest2ViewController.swift | 60 ++--- .../FOLTest3ViewController.swift | 4 +- .../FOLTest4ViewController.swift | 6 +- .../FLLTest1ViewController.swift | 12 +- .../FLLTest2ViewController.swift | 10 +- .../FLLTest3ViewController.swift | 12 +- .../FLLTest6ViewController.swift | 2 +- TangramKitDemo/Info.plist | 6 +- .../AllTest1ViewController.swift | 8 +- .../AllTest2ViewController.swift | 2 +- .../AllTest3ViewController.swift | 28 +-- .../AllTest4ViewController.swift | 4 +- .../AllTest7ViewController.swift | 12 +- .../AllTest8ViewController.swift | 6 +- .../AllTest1TableViewHeaderFooterView.swift | 2 +- .../PLTest1ViewController.swift | 32 +-- .../PLTest2ViewController.swift | 8 +- .../PLTest3ViewController.swift | 2 +- .../PLTest4ViewController.swift | 2 +- .../RLTest2ViewController.swift | 4 +- .../RLTest5ViewController.swift | 4 +- .../zh-Hans.lproj/Localizable.strings | 4 +- .../TLTest1ViewController.swift | 24 +- .../TLTest2ViewController.swift | 4 +- .../TLTest3ViewController.swift | 4 +- TangramKitDemo/ViewController.swift | 5 +- .../LLTest1ViewController.swift | 13 ++ .../LLTest2ViewController.swift | 4 +- .../LLTest3ViewController.swift | 8 +- .../LLTest4ViewController.swift | 2 +- .../LLTest6ViewController.swift | 2 +- .../LLTest7ViewController.swift | 2 +- 52 files changed, 903 insertions(+), 551 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d20779..eb391b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,30 @@ --- +## [V1.1.2](https://github.com/youngsoft/TangramKit/releases/tag/1.1.2)(2017/9/23) + +#### Added +1. 添加对Swift4的兼容支持 +2. 添加适配iOS11的能力以及**iPhoneX**的方法。基本不需要改动当前代码。如果需要改动只需要设置根布局视图的一些属性即可。 + 1. 新增布局视图属性:`tg_insetsPaddingFromSafeArea`用来设置在哪个方向缩进对应方向的安全区域。 + 2. 新增布局视图属性:`tg_insetLandscapeFringePadding`用来设置当支持横屏时,并且tg_insetsPaddingFromSafeArea设置为左右缩进时,是否只缩进有刘海的那一边。这个属性默认设置为NO,表示两边都缩进。您可以在特殊需要时将这个属性设置为YES表示只缩进刘海那一边,非刘海那一边则不缩进。具体参考使用DEMO:[LLTest1ViewController](https://github.com/youngsoft/TangramKit/blob/master/TangramKitDemo/linerLayoutDemo/LLTest1ViewController.swift) + +3. 表格布局TGTableLayout添加了`tg_addRow:colCount:`方法,目的是为了支持那些列数固定并且宽度固定的需求,具体例子见DEMO:[TLTest1ViewController](https://github.com/youngsoft/TangramKit/blob/master/TangramKitDemo/TableLayoutDemo/TLTest1ViewController.swift)中的第五行的代码。 +4. 添加了布局视图的高度等于非布局父视图宽度以及布局视图宽度等于非布局父视图高度的支持,目的是为了支持对布局视图进行旋转`transform`的支持。 +5. 添加了框架布局MyFrameLayout中子视图的高度等于另外视图宽度以及宽度等于另外视图高度的支持。 +6. 下一个版本将会有重大功能的添加:栅格布局的支持、基线对齐的支持、均分的再次优化等等功能,敬请期待吧。。 + + + +#### Fixed +1. 修复了流式布局`MyFlowLayout`中当使用`pageCount`设置分页而里面的子视图是布局视图并设置了wrapContentHeight或wrapContentWidth方法时有可能会导致约束冲突而产生死循环的问题。 + +2. 修复了线性布局中的子视图设置为weight=1来均分布局视图的尺寸时,有可能导致产生中间缝隙的BUG。以及子视图的总尺寸和布局视图尺寸不相等的BUG。 +3. 修复了当对布局视图进行多点触摸且设置了布局视图的触摸事件时,有可能会对对应的触摸动作不调用而产生触摸状态无法被恢复的问题。 +4. 调整了将原始逻辑点转化为可显示逻辑点的算法,老算法计算可能不精确。 + + + ## [V1.1.1](https://github.com/youngsoft/TangramKit/releases/tag/1.1.1)(2017/6/22) #### Fixed 1. 修复了布局视图套布局视图,并且尺寸是.wrap时界面有可能进入死循环的问题,尤其是iPhonePlus设备。 diff --git a/README.md b/README.md index 42a0f07..2be8405 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.1' +pod 'TangramKit', '~> 1.1.2' ``` Then, run the following command: diff --git a/README.zh.md b/README.zh.md index d4c4783..e935289 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.1' +pod 'TangramKit', '~> 1.1.2' ``` 然后运行如下命令: diff --git a/TangramKit.podspec b/TangramKit.podspec index d684def..cff266e 100644 --- a/TangramKit.podspec +++ b/TangramKit.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "TangramKit" - s.version = "1.1.1" + s.version = "1.1.2" 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 @@ -67,11 +67,6 @@ Pod::Spec.new do |s| # s.platform = :ios s.platform = :ios, "8.0" - # When using multiple platforms - # s.ios.deployment_target = "5.0" - # s.osx.deployment_target = "10.7" - # s.watchos.deployment_target = "2.0" - # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # @@ -79,7 +74,7 @@ Pod::Spec.new do |s| # Supports git, hg, bzr, svn and HTTP. # - s.source = { :git => "https://github.com/youngsoft/TangramKit.git", :tag => "1.1.1" } + s.source = { :git => "https://github.com/youngsoft/TangramKit.git", :tag => s.version } # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # @@ -93,45 +88,5 @@ Pod::Spec.new do |s| s.source_files = "TangramKit/*.{swift}" #s.exclude_files = "Classes/Exclude" - #s.public_header_files = "TangramKit/Lib/*.h" - - - # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # A list of resources included with the Pod. These are copied into the - # target bundle with a build phase script. Anything else will be cleaned. - # You can preserve files from being cleaned, please don't preserve - # non-essential files like tests, examples and documentation. - # - - # s.resource = "icon.png" - # s.resources = "Resources/*.png" - - # s.preserve_paths = "FilesToSave", "MoreFilesToSave" - - - # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # Link your library with frameworks, or libraries. Libraries do not include - # the lib prefix of their name. - # - - # s.framework = "SomeFramework" - # s.frameworks = "SomeFramework", "AnotherFramework" - - # s.library = "iconv" - # s.libraries = "iconv", "xml2" - - - # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - # - # If your library depends on compiler flags you can set them in the xcconfig hash - # where they will only apply to your library. If you depend on other Podspecs - # you can include multiple dependencies to ensure it works. - - # s.requires_arc = true - - # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } - # s.dependency "JSONKit", "~> 1.4" end diff --git a/TangramKit.xcodeproj/project.pbxproj b/TangramKit.xcodeproj/project.pbxproj index 2274e32..915d09b 100644 --- a/TangramKit.xcodeproj/project.pbxproj +++ b/TangramKit.xcodeproj/project.pbxproj @@ -106,9 +106,9 @@ 681BD9011E0B92E100403A1F /* TangramKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TangramKit.swift; sourceTree = ""; }; 681BD9021E0B92E100403A1F /* TGBaseLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = TGBaseLayout.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 681BD9031E0B92E100403A1F /* TGDimeAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TGDimeAdapter.swift; sourceTree = ""; }; - 681BD9041E0B92E100403A1F /* TGFloatLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TGFloatLayout.swift; sourceTree = ""; }; - 681BD9051E0B92E100403A1F /* TGFlowLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TGFlowLayout.swift; sourceTree = ""; }; - 681BD9061E0B92E100403A1F /* TGFrameLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TGFrameLayout.swift; sourceTree = ""; }; + 681BD9041E0B92E100403A1F /* TGFloatLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = TGFloatLayout.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 681BD9051E0B92E100403A1F /* TGFlowLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = TGFlowLayout.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 681BD9061E0B92E100403A1F /* TGFrameLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = TGFrameLayout.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 681BD9071E0B92E100403A1F /* TGLayoutPos.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = TGLayoutPos.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 681BD9081E0B92E100403A1F /* TGLayoutSize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TGLayoutSize.swift; sourceTree = ""; }; 681BD9091E0B92E100403A1F /* TGLayoutSizeClass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = TGLayoutSizeClass.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -444,12 +444,15 @@ TargetAttributes = { 18270C231C954B3C00CBCC92 = { CreatedOnToolsVersion = 7.2; - DevelopmentTeam = Q5MFLFRY64; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; + SystemCapabilities = { + com.apple.BackgroundModes = { + enabled = 1; + }; + }; }; 681BD8DA1E0B91A500403A1F = { CreatedOnToolsVersion = 8.2; - DevelopmentTeam = Q5MFLFRY64; LastSwiftMigration = 0820; ProvisioningStyle = Automatic; }; @@ -726,18 +729,19 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - DEVELOPMENT_TEAM = Q5MFLFRY64; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ""; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = TangramKit/TangramKitDemo/TangramKitPrefix.pch; INFOPLIST_FILE = "$(SRCROOT)/TangramKitDemo/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.bbae.anno.dev; + PRODUCT_BUNDLE_IDENTIFIER = com.youngsoft.TangramKit.demo; PRODUCT_NAME = TangramKitDemo; SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -746,18 +750,19 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - DEVELOPMENT_TEAM = Q5MFLFRY64; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ""; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = TangramKit/TangramKitDemo/TangramKitPrefix.pch; INFOPLIST_FILE = "$(SRCROOT)/TangramKitDemo/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.bbae.anno.dev; + PRODUCT_BUNDLE_IDENTIFIER = com.youngsoft.TangramKit.demo; PRODUCT_NAME = TangramKitDemo; SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -770,7 +775,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = Q5MFLFRY64; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -779,7 +784,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACH_O_TYPE = mh_dylib; - PRODUCT_BUNDLE_IDENTIFIER = com.hanwp.TangramKit; + PRODUCT_BUNDLE_IDENTIFIER = com.youngsoft.TangramKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; @@ -799,7 +804,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = Q5MFLFRY64; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -808,7 +813,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MACH_O_TYPE = mh_dylib; - PRODUCT_BUNDLE_IDENTIFIER = com.hanwp.TangramKit; + PRODUCT_BUNDLE_IDENTIFIER = com.youngsoft.TangramKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/TangramKit/Info.plist b/TangramKit/Info.plist index 95d9477..c5ddeda 100644 --- a/TangramKit/Info.plist +++ b/TangramKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.1.1 + 1.1.2 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/TangramKit/TGBaseLayout.swift b/TangramKit/TGBaseLayout.swift index 9f2b3a2..9519f84 100644 --- a/TangramKit/TGBaseLayout.swift +++ b/TangramKit/TGBaseLayout.swift @@ -852,6 +852,44 @@ open class TGBaseLayout: UIView,TGLayoutViewSizeClass { } } + /** + 指定padding内边距的缩进是在SafeArea基础之上进行的。默认是.all表示四周都会缩进SafeArea所指定的区域。你也可以设置只缩进某一个或则几个方向,或者不缩进任何一个方向。这个属性是为了支持iPoneX而设置的。为了支持iPhoneX的全屏幕适配。我们只需要对根布局视图设置这个扩展属性,默认情况下是不需要进行特殊设置的,TangramKit自动会对iPhoneX进行适配。我们知道iOS11中引入了安全区域的概念,TangramKit中的根布局视图会自动将安全区域叠加到设置的padding中去。默认情况下四周的安全区域都会叠加到padding中去,因此您可以根据特殊情况来设置只需要叠加哪一个方向的安全区域。 + */ + public var tg_insetsPaddingFromSafeArea:UIRectEdge + { + get{ + return (self.tgCurrentSizeClass as! TGLayoutViewSizeClass).tg_insetsPaddingFromSafeArea + } + set + { + let lsc = self.tgCurrentSizeClass as! TGLayoutViewSizeClass + if lsc.tg_insetsPaddingFromSafeArea != newValue + { + lsc.tg_insetsPaddingFromSafeArea = newValue + setNeedsLayout() + } + } + } + + /** + *当tg_insetsPaddingFromSafeArea同时设置有左右方向同时缩进并且在横屏时是否只缩进有刘海方向的内边距。默认是false,表示两边都会缩进。如果你想让没有刘海的那一边延伸到屏幕的安全区外,请将这个属性设置为true。iPhoneX设备中具有一个尺寸为44的刘海区域。当您横屏时为了对齐,左右两边的安全缩进区域都是44。但是有些时候我们希望没有刘海的那一边不需要缩进对齐而是延伸到安全区域以外。这时候您可以通过给根布局视图设置这个属性来达到效果。注意这个属性只有tg_insetsPaddingFromSafeArea设置了左右都缩进时才有效。 + */ + public var tg_insetLandscapeFringePadding:Bool + { + get{ + return (self.tgCurrentSizeClass as! TGLayoutViewSizeClass).tg_insetLandscapeFringePadding + } + set + { + let lsc = self.tgCurrentSizeClass as! TGLayoutViewSizeClass + if lsc.tg_insetLandscapeFringePadding != newValue + { + lsc.tg_insetLandscapeFringePadding = newValue + setNeedsLayout() + } + } + } + /** 定义布局视图内子视图之间的间距,所谓间距就是子视图之间的间隔距离。 @@ -2116,11 +2154,13 @@ extension TGBaseLayout { if (t.type == TGGravity.horz.fill) { - value = selfLayoutSize.width - (t.view == self ? (self.tg_leadingPadding + self.tg_trailingPadding) : 0); + let lsc = self.tgCurrentSizeClass as! TGLayoutViewSizeClassImpl + value = selfLayoutSize.width - (t.view == self ? (lsc.tgLeadingPadding + lsc.tgTrailingPadding) : 0); } else { - value = selfLayoutSize.height - (t.view == self ? (self.tg_topPadding + self.tg_bottomPadding) :0); + let lsc = self.tgCurrentSizeClass as! TGLayoutViewSizeClassImpl + value = selfLayoutSize.height - (t.view == self ? (lsc.tgTopPadding + lsc.tgBottomPadding) :0); } } else if (t.view == sbv) @@ -2407,7 +2447,15 @@ extension TGBaseLayout { if t.view === newSuperview { - rectSelf.size.width = lsc.width.measure(rectSuper.width) + if t.type == TGGravity.horz.fill + { + rectSelf.size.width = lsc.width.measure(rectSuper.width) + } + else + { + rectSelf.size.width = lsc.width.measure(rectSuper.height) + } + } else { @@ -2476,7 +2524,14 @@ extension TGBaseLayout { if t.view === newSuperview { - rectSelf.size.height = lsc.height.measure(rectSuper.height) + if t.type == TGGravity.vert.fill + { + rectSelf.size.height = lsc.height.measure(rectSuper.height) + } + else + { + rectSelf.size.height = lsc.height.measure(rectSuper.width) + } } else { @@ -2573,11 +2628,11 @@ extension TGBaseLayout { if lsc.width.isWrap { - size.width -= (lsc.tg_leadingPadding + lsc.tg_trailingPadding) + size.width -= (lsc.tgLeadingPadding + lsc.tgTrailingPadding) } if lsc.height.isWrap { - size.height -= (lsc.tg_topPadding + lsc.tg_bottomPadding) + size.height -= (lsc.tgTopPadding + lsc.tgBottomPadding) } } @@ -2711,19 +2766,19 @@ extension TGBaseLayout internal func tgCalcVertGravity(_ vert:TGGravity, selfSize:CGSize, sbv:UIView, sbvsc:TGViewSizeClassImpl, lsc:TGLayoutViewSizeClassImpl, rect:inout CGRect) { - let fixedHeight = lsc.tg_topPadding + lsc.tg_bottomPadding + let fixedHeight = lsc.tgTopPadding + lsc.tgBottomPadding let topMargin = sbvsc.top.weightPosIn(selfSize.height - fixedHeight) let centerMargin = sbvsc.centerY.weightPosIn(selfSize.height - fixedHeight) let bottomMargin = sbvsc.bottom.weightPosIn(selfSize.height - fixedHeight) if vert == TGGravity.vert.fill { - rect.origin.y = lsc.tg_topPadding + topMargin; + rect.origin.y = lsc.tgTopPadding + topMargin; rect.size.height = self.tgValidMeasure(sbvsc.height, sbv: sbv, calcSize:selfSize.height - fixedHeight - topMargin - bottomMargin , sbvSize: rect.size, selfLayoutSize: selfSize) } else if vert == TGGravity.vert.center { - rect.origin.y = (selfSize.height - fixedHeight - topMargin - bottomMargin - rect.size.height)/2 + lsc.tg_topPadding + topMargin + centerMargin; + rect.origin.y = (selfSize.height - fixedHeight - topMargin - bottomMargin - rect.size.height)/2 + lsc.tgTopPadding + topMargin + centerMargin; } else if vert == TGGravity.vert.windowCenter { @@ -2737,11 +2792,11 @@ extension TGBaseLayout else if vert == TGGravity.vert.bottom { - rect.origin.y = selfSize.height - lsc.tg_bottomPadding - bottomMargin - rect.size.height; + rect.origin.y = selfSize.height - lsc.tgBottomPadding - bottomMargin - rect.size.height; } else { - rect.origin.y = lsc.tg_topPadding + topMargin; + rect.origin.y = lsc.tgTopPadding + topMargin; } } @@ -2790,7 +2845,7 @@ extension TGBaseLayout internal func tgCalcHorzGravity(_ horz:TGGravity, selfSize:CGSize, sbv:UIView, sbvsc:TGViewSizeClassImpl, lsc:TGLayoutViewSizeClassImpl, rect:inout CGRect) { - let fixedWidth = lsc.tg_leadingPadding + lsc.tg_trailingPadding + let fixedWidth = lsc.tgLeadingPadding + lsc.tgTrailingPadding let leadingMargin = sbvsc.leading.weightPosIn(selfSize.width - fixedWidth) let centerMargin = sbvsc.centerX.weightPosIn(selfSize.width - fixedWidth) let trailingMargin = sbvsc.trailing.weightPosIn(selfSize.width - fixedWidth) @@ -2798,12 +2853,12 @@ extension TGBaseLayout if horz == TGGravity.horz.fill { - rect.origin.x = lsc.tg_leadingPadding + leadingMargin; + rect.origin.x = lsc.tgLeadingPadding + leadingMargin; rect.size.width = self.tgValidMeasure(sbvsc.width, sbv: sbv, calcSize:selfSize.width - fixedWidth - leadingMargin - trailingMargin , sbvSize: rect.size, selfLayoutSize: selfSize) } else if horz == TGGravity.horz.center { - rect.origin.x = (selfSize.width - fixedWidth - leadingMargin - trailingMargin - rect.size.width)/2 + lsc.tg_leadingPadding + leadingMargin + centerMargin; + rect.origin.x = (selfSize.width - fixedWidth - leadingMargin - trailingMargin - rect.size.width)/2 + lsc.tgLeadingPadding + leadingMargin + centerMargin; } else if horz == TGGravity.horz.windowCenter { @@ -2822,11 +2877,11 @@ extension TGBaseLayout else if horz == TGGravity.horz.trailing { - rect.origin.x = selfSize.width - lsc.tg_trailingPadding - trailingMargin - rect.size.width; + rect.origin.x = selfSize.width - lsc.tgTrailingPadding - trailingMargin - rect.size.width; } else { - rect.origin.x = lsc.tg_leadingPadding + leadingMargin; + rect.origin.x = lsc.tgLeadingPadding + leadingMargin; } } @@ -2899,11 +2954,11 @@ extension TGBaseLayout if t === lsc.width.realSize && !lsc.width.isWrap { - rect.size.width = dime.measure(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + rect.size.width = dime.measure(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) } else if t === lsc.height.realSize { - rect.size.width = dime.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.width = dime.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) } else if t === sbvsc.height.realSize { @@ -2922,11 +2977,11 @@ extension TGBaseLayout { if t === lsc.height.realSize && !lsc.height.isWrap { - rect.size.height = dime.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.height = dime.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) } else if t === lsc.width.realSize { - rect.size.height = dime.measure(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + rect.size.height = dime.measure(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) } else if t === sbvsc.width.realSize { @@ -3168,16 +3223,18 @@ private class TGTouchEventDelegate private var _hasDoCancel:Bool = false private var _oldBackgroundColor:UIColor?=nil private var _oldBackgroundImage:UIImage?=nil - private var _oldAlpha:CGFloat = 0 + private var _oldAlpha:CGFloat = 1 private var _forbidTouch:Bool = false private var _canCallAction:Bool = false private var _beginPoint:CGPoint = .zero static var _HasBegin:Bool = false + static weak var _CurrentLayout:TGBaseLayout! = nil init(_ layout: TGBaseLayout) { _layout = layout + TGTouchEventDelegate._CurrentLayout = nil } func setTarget(_ target: NSObjectProtocol?, action: Selector?, for controlEvents: UIControlEvents) @@ -3209,6 +3266,7 @@ private class TGTouchEventDelegate if _layout != nil && _touchUpTarget != nil && !_forbidTouch && touch.tapCount == 1 && !TGTouchEventDelegate._HasBegin { TGTouchEventDelegate._HasBegin = true + TGTouchEventDelegate._CurrentLayout = _layout _canCallAction = true _beginPoint = touch.location(in: _layout) @@ -3223,7 +3281,7 @@ private class TGTouchEventDelegate func touchesMoved(_ touches: Set, with event: UIEvent?) { - if _layout != nil && _touchUpTarget != nil && TGTouchEventDelegate._HasBegin + if _layout != nil && _touchUpTarget != nil && TGTouchEventDelegate._HasBegin && (_layout === TGTouchEventDelegate._CurrentLayout || TGTouchEventDelegate._CurrentLayout == nil) { if _canCallAction { @@ -3248,7 +3306,7 @@ private class TGTouchEventDelegate func touchesEnded(_ touches: Set, with event: UIEvent?) { - if _layout != nil && _touchUpTarget != nil && TGTouchEventDelegate._HasBegin + if _layout != nil && _touchUpTarget != nil && TGTouchEventDelegate._HasBegin && (_layout === TGTouchEventDelegate._CurrentLayout || TGTouchEventDelegate._CurrentLayout == nil) { //设置一个延时. _forbidTouch = true @@ -3261,19 +3319,21 @@ private class TGTouchEventDelegate }) TGTouchEventDelegate._HasBegin = false + TGTouchEventDelegate._CurrentLayout = nil } } func touchesCancelled(_ touches: Set, with event: UIEvent?) { - if _layout != nil && _touchUpTarget != nil && TGTouchEventDelegate._HasBegin + if _layout != nil && _touchUpTarget != nil && TGTouchEventDelegate._HasBegin && (_layout === TGTouchEventDelegate._CurrentLayout || TGTouchEventDelegate._CurrentLayout == nil) { self.resetTouchHighlighted() TGTouchEventDelegate._HasBegin = false - + TGTouchEventDelegate._CurrentLayout = nil + if !_hasDoCancel { _ = _touchCancelTarget?.perform(_touchCancelAction, with: _layout) @@ -3293,7 +3353,7 @@ private class TGTouchEventDelegate //距离太远则不会处理 let pt:CGPoint = touch.location(in: _layout) - if _touchUpTarget != nil && _canCallAction && _layout.bounds.contains(pt) + if _touchUpTarget != nil && _touchUpAction != nil && _canCallAction && _layout.bounds.contains(pt) { _ = _touchUpTarget?.perform(_touchUpAction, with: _layout) } @@ -3964,7 +4024,7 @@ extension UIView - func tgCreateInstance() -> AnyObject + @objc func tgCreateInstance() -> AnyObject { return TGViewSizeClassImpl(view:self) } @@ -4091,22 +4151,16 @@ internal func _tgRoundNumber(_ f :CGFloat) ->CGFloat } - let fi = rint(f) - if _tgCGFloatEqual(fi, f) - { - return fi - } - //按精度四舍五入 //正确的算法应该是。x = 0; y = 0; 0= 0 @@ -332,7 +332,7 @@ extension TGFloatLayout var retPoint = CGPoint(x: CGFloat.greatestFiniteMagnitude,y: bottomBoundary) - var lastWidth = lsc.tg_leadingPadding; + var lastWidth = lsc.tgLeadingPadding; var i = bottomCandidateRects.count - 1 while i >= 0 { @@ -379,7 +379,7 @@ extension TGFloatLayout var retPoint = CGPoint(x: leadingBoundary,y: CGFloat.greatestFiniteMagnitude) - var lastHeight = lsc.tg_topPadding; + var lastHeight = lsc.tgTopPadding; var i = leadingCandidateRects.count - 1 while i >= 0 { @@ -424,7 +424,7 @@ extension TGFloatLayout var retPoint = CGPoint(x: CGFloat.greatestFiniteMagnitude, y: topBoundary) - var lastWidth = lsc.tg_leadingPadding; + var lastWidth = lsc.tgLeadingPadding; var i = topCandidateRects.count - 1 while i >= 0 { @@ -484,7 +484,7 @@ extension TGFloatLayout //遍历所有的子视图,查看是否有子视图的宽度会比视图自身要宽,如果有且有包裹属性则扩充自身的宽度 if (lsc.width.isWrap && hasBoundaryLimit) { - var maxContentWidth = selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding; + var maxContentWidth = selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding; for sbv in sbs { let (sbvtgFrame, sbvsc) = self.tgGetSubviewFrameAndSizeClass(sbv) @@ -500,7 +500,7 @@ extension TGFloatLayout rect.size.height = sbvsc.height.numberSize(rect.size.height) if sbvsc.height.isRelaSizeEqualTo(lsc.height) { - rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) } rect.size.height = self.tgValidMeasure(sbvsc.height, sbv: sbv, calcSize: rect.size.height, sbvSize: rect.size, selfLayoutSize: selfSize) @@ -519,7 +519,7 @@ extension TGFloatLayout } } - selfSize.width = lsc.tg_leadingPadding + maxContentWidth + lsc.tg_trailingPadding; + selfSize.width = lsc.tgLeadingPadding + maxContentWidth + lsc.tgTrailingPadding; } let vertSpace = lsc.tg_vspace; @@ -536,16 +536,16 @@ extension TGFloatLayout let maxSpace = lsc.maxSpace - let rowCount = floor((selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding + minSpace) / (subviewSize + minSpace)); + let rowCount = floor((selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding + minSpace) / (subviewSize + minSpace)); if (rowCount > 1) { - horzSpace = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - subviewSize * rowCount)/(rowCount - 1); + horzSpace = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - subviewSize * rowCount)/(rowCount - 1); if _tgCGFloatGreat(horzSpace , maxSpace) { horzSpace = maxSpace - subviewSize = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - horzSpace * (rowCount - 1)) / rowCount + subviewSize = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - horzSpace * (rowCount - 1)) / rowCount } } } @@ -554,22 +554,22 @@ extension TGFloatLayout //左边候选区域数组,保存的是CGRect值。 var leadingCandidateRects:[CGRect] = [CGRect]() //为了计算方便总是把最左边的个虚拟区域作为一个候选区域 - leadingCandidateRects.append(CGRect(x: lsc.tg_leadingPadding, y: lsc.tg_topPadding, width: 0, height: CGFloat.greatestFiniteMagnitude)); + leadingCandidateRects.append(CGRect(x: lsc.tgLeadingPadding, y: lsc.tgTopPadding, width: 0, height: CGFloat.greatestFiniteMagnitude)); //右边候选区域数组,保存的是CGRect值。 var trailingCandidateRects:[CGRect] = [CGRect]() //为了计算方便总是把最右边的个虚拟区域作为一个候选区域 - trailingCandidateRects.append(CGRect(x: selfSize.width - lsc.tg_trailingPadding, y: lsc.tg_topPadding, width: 0, height: CGFloat.greatestFiniteMagnitude)); + trailingCandidateRects.append(CGRect(x: selfSize.width - lsc.tgTrailingPadding, y: lsc.tgTopPadding, width: 0, height: CGFloat.greatestFiniteMagnitude)); //分别记录左边和右边的最后一个视图在Y轴的偏移量 - var leadingLastYOffset = lsc.tg_topPadding - var trailingLastYOffset = lsc.tg_topPadding + var leadingLastYOffset = lsc.tgTopPadding + var trailingLastYOffset = lsc.tgTopPadding //分别记录左右边和全局浮动视图的最高占用的Y轴的值 - var leadingMaxHeight = lsc.tg_topPadding - var trailingMaxHeight = lsc.tg_topPadding - var maxHeight = lsc.tg_topPadding - var maxWidth = lsc.tg_leadingPadding + var leadingMaxHeight = lsc.tgTopPadding + var trailingMaxHeight = lsc.tgTopPadding + var maxHeight = lsc.tgTopPadding + var maxWidth = lsc.tgLeadingPadding for sbv in sbs { @@ -594,17 +594,17 @@ extension TGFloatLayout if isHeightWeight && !lsc.height.isWrap { - rect.size.height = sbvsc.height.measure((selfSize.height - maxHeight - lsc.tg_bottomPadding) * (sbvsc.height.isFill ? 1.0 : sbvsc.height.weightVal.rawValue/100) - topSpace - bottomSpace) + rect.size.height = sbvsc.height.measure((selfSize.height - maxHeight - lsc.tgBottomPadding) * (sbvsc.height.isFill ? 1.0 : sbvsc.height.weightVal.rawValue/100) - topSpace - bottomSpace) } if sbvsc.height.isRelaSizeEqualTo(lsc.height) && !lsc.height.isWrap { - rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) } if sbvsc.width.isRelaSizeEqualTo(lsc.width) { - rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) } rect.size.width = self.tgValidMeasure(sbvsc.width, sbv: sbv, calcSize: rect.size.width, sbvSize: rect.size, selfLayoutSize: selfSize) @@ -648,14 +648,14 @@ extension TGFloatLayout assert(hasBoundaryLimit, "Constraint exception!!, vertical float layout:\(self) can not set tg_noBoundaryLimit to true when the subview:\(sbv) set tg_reverseFloat to true.") #endif - var nextPoint = CGPoint(x: selfSize.width - lsc.tg_trailingPadding, y: leadingLastYOffset); - var leadingCandidateXBoundary = lsc.tg_leadingPadding; + var nextPoint = CGPoint(x: selfSize.width - lsc.tgTrailingPadding, y: leadingLastYOffset); + var leadingCandidateXBoundary = lsc.tgLeadingPadding; if (sbvsc.tg_clearFloat) { //找到最底部的位置。 nextPoint.y = max(trailingMaxHeight, leadingLastYOffset); - let leftPoint = self.tgFindLeadingCandidatePoint(CGRect(x: selfSize.width - lsc.tg_trailingPadding, y: nextPoint.y, width: 0, height: CGFloat.greatestFiniteMagnitude), width:leadingSpace + (isWidthWeight ? 0 : rect.size.width) + trailingSpace,leadingBoundary:lsc.tg_leadingPadding,leadingCandidateRects:leadingCandidateRects,hasWeight:isWidthWeight, lsc:lsc) + let leftPoint = self.tgFindLeadingCandidatePoint(CGRect(x: selfSize.width - lsc.tgTrailingPadding, y: nextPoint.y, width: 0, height: CGFloat.greatestFiniteMagnitude), width:leadingSpace + (isWidthWeight ? 0 : rect.size.width) + trailingSpace,leadingBoundary:lsc.tgLeadingPadding,leadingCandidateRects:leadingCandidateRects,hasWeight:isWidthWeight, lsc:lsc) if (leftPoint.y != CGFloat.greatestFiniteMagnitude) { nextPoint.y = max(trailingMaxHeight, leftPoint.y); @@ -669,7 +669,7 @@ extension TGFloatLayout while i >= 0 { let candidateRect = trailingCandidateRects[i] - let leftPoint = self.tgFindLeadingCandidatePoint(candidateRect,width:leadingSpace + (isWidthWeight ? 0 : rect.size.width) + trailingSpace,leadingBoundary:lsc.tg_leadingPadding, leadingCandidateRects:leadingCandidateRects,hasWeight:isWidthWeight, lsc:lsc) + let leftPoint = self.tgFindLeadingCandidatePoint(candidateRect,width:leadingSpace + (isWidthWeight ? 0 : rect.size.width) + trailingSpace,leadingBoundary:lsc.tgLeadingPadding, leadingCandidateRects:leadingCandidateRects,hasWeight:isWidthWeight, lsc:lsc) if (leftPoint.y != CGFloat.greatestFiniteMagnitude) { nextPoint = CGPoint(x: candidateRect.minX, y: max(nextPoint.y, leftPoint.y)); @@ -724,12 +724,12 @@ extension TGFloatLayout sbvl.tg_trailingBorderline = nil; sbvl.tg_leadingBorderline = nil; - if _tgCGFloatLess(rect.origin.x + rect.size.width + trailingSpace , selfSize.width - lsc.tg_trailingPadding) + if _tgCGFloatLess(rect.origin.x + rect.size.width + trailingSpace , selfSize.width - lsc.tgTrailingPadding) { sbvl.tg_trailingBorderline = self.tg_intelligentBorderline; } - if _tgCGFloatLess(rect.origin.y + rect.size.height + bottomSpace , selfSize.height - lsc.tg_bottomPadding) + if _tgCGFloatLess(rect.origin.y + rect.size.height + bottomSpace , selfSize.height - lsc.tgBottomPadding) { sbvl.tg_bottomBorderline = self.tg_intelligentBorderline; } @@ -746,7 +746,7 @@ extension TGFloatLayout //这里有可能子视图本身的宽度会超过布局视图本身,但是我们的候选区域则不存储超过的宽度部分。 - var cRect = CGRect(x: max(rect.origin.x - leadingSpace - horzSpace,lsc.tg_leadingPadding), y: rect.origin.y - topSpace, width: min((rect.size.width + leadingSpace + trailingSpace),(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding)), height: rect.size.height + topSpace + bottomSpace + vertSpace); + var cRect = CGRect(x: max(rect.origin.x - leadingSpace - horzSpace,lsc.tgLeadingPadding), y: rect.origin.y - topSpace, width: min((rect.size.width + leadingSpace + trailingSpace),(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding)), height: rect.size.height + topSpace + bottomSpace + vertSpace); //把新的候选区域添加到数组中去。并删除高度小于新候选区域的其他区域 @@ -789,8 +789,8 @@ extension TGFloatLayout } else { - var nextPoint = CGPoint(x: lsc.tg_leadingPadding, y: trailingLastYOffset) - var trailingCandidateXBoundary = selfSize.width - lsc.tg_trailingPadding; + var nextPoint = CGPoint(x: lsc.tgLeadingPadding, y: trailingLastYOffset) + var trailingCandidateXBoundary = selfSize.width - lsc.tgTrailingPadding; //如果是清除了浮动则直换行移动到最下面。 if (sbvsc.tg_clearFloat) @@ -798,7 +798,7 @@ extension TGFloatLayout //找到最低点。 nextPoint.y = max(leadingMaxHeight, trailingLastYOffset); - let rightPoint = self.tgFindTrailingCandidatePoint(CGRect(x: lsc.tg_leadingPadding, y: nextPoint.y, width: 0, height: CGFloat.greatestFiniteMagnitude), width:leadingSpace + (isWidthWeight ? 0 : rect.size.width) + trailingSpace, trailingBoundary:trailingCandidateXBoundary, trailingCandidateRects:trailingCandidateRects, hasWeight:isWidthWeight, lsc:lsc) + let rightPoint = self.tgFindTrailingCandidatePoint(CGRect(x: lsc.tgLeadingPadding, y: nextPoint.y, width: 0, height: CGFloat.greatestFiniteMagnitude), width:leadingSpace + (isWidthWeight ? 0 : rect.size.width) + trailingSpace, trailingBoundary:trailingCandidateXBoundary, trailingCandidateRects:trailingCandidateRects, hasWeight:isWidthWeight, lsc:lsc) if (rightPoint.y != CGFloat.greatestFiniteMagnitude) { nextPoint.y = max(leadingMaxHeight, rightPoint.y); @@ -813,7 +813,7 @@ extension TGFloatLayout while i >= 0 { let candidateRect = leadingCandidateRects[i] - let rightPoint = self.tgFindTrailingCandidatePoint(candidateRect, width:leadingSpace + (isWidthWeight ? 0 : rect.size.width) + trailingSpace,trailingBoundary:selfSize.width - lsc.tg_trailingPadding,trailingCandidateRects:trailingCandidateRects,hasWeight:isWidthWeight,lsc:lsc) + let rightPoint = self.tgFindTrailingCandidatePoint(candidateRect, width:leadingSpace + (isWidthWeight ? 0 : rect.size.width) + trailingSpace,trailingBoundary:selfSize.width - lsc.tgTrailingPadding,trailingCandidateRects:trailingCandidateRects,hasWeight:isWidthWeight,lsc:lsc) if (rightPoint.y != CGFloat.greatestFiniteMagnitude) { nextPoint = CGPoint(x: candidateRect.maxX, y: max(nextPoint.y, rightPoint.y)); @@ -876,12 +876,12 @@ extension TGFloatLayout sbvl.tg_leadingBorderline = nil; //如果自己的上边和左边有子视图。 - if _tgCGFloatGreat(rect.origin.x - leadingSpace, lsc.tg_leadingPadding) + if _tgCGFloatGreat(rect.origin.x - leadingSpace, lsc.tgLeadingPadding) { sbvl.tg_leadingBorderline = self.tg_intelligentBorderline; } - if _tgCGFloatGreat(rect.origin.y - topSpace, lsc.tg_topPadding) + if _tgCGFloatGreat(rect.origin.y - topSpace, lsc.tgTopPadding) { sbvl.tg_topBorderline = self.tg_intelligentBorderline; } @@ -892,7 +892,7 @@ extension TGFloatLayout - var cRect = CGRect(x: rect.origin.x - leadingSpace, y: rect.origin.y - topSpace, width: min((rect.size.width + leadingSpace + trailingSpace + horzSpace),(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding)), height: rect.size.height + topSpace + bottomSpace + vertSpace); + var cRect = CGRect(x: rect.origin.x - leadingSpace, y: rect.origin.y - topSpace, width: min((rect.size.width + leadingSpace + trailingSpace + horzSpace),(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding)), height: rect.size.height + topSpace + bottomSpace + vertSpace); //把新添加到候选中去。并删除高度小于的候选键。和高度 @@ -953,8 +953,8 @@ extension TGFloatLayout maxWidth -= horzSpace } - maxHeight += lsc.tg_bottomPadding - maxWidth += lsc.tg_trailingPadding + maxHeight += lsc.tgBottomPadding + maxWidth += lsc.tgTrailingPadding if !hasBoundaryLimit { @@ -1010,7 +1010,7 @@ extension TGFloatLayout //遍历所有的子视图,查看是否有子视图的宽度会比视图自身要宽,如果有且有包裹属性则扩充自身的宽度 if (lsc.height.isWrap && hasBoundaryLimit) { - var maxContentHeight = selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding; + var maxContentHeight = selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding; for sbv in sbs { let (sbvtgFrame, sbvsc) = self.tgGetSubviewFrameAndSizeClass(sbv) @@ -1032,7 +1032,7 @@ extension TGFloatLayout if sbvsc.width.isRelaSizeEqualTo(lsc.width) { - rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) } rect.size.width = self.tgValidMeasure(sbvsc.width, sbv: sbv, calcSize: rect.size.width, sbvSize: rect.size, selfLayoutSize: selfSize) @@ -1058,7 +1058,7 @@ extension TGFloatLayout } } - selfSize.height = lsc.tg_topPadding + maxContentHeight + lsc.tg_bottomPadding; + selfSize.height = lsc.tgTopPadding + maxContentHeight + lsc.tgBottomPadding; } @@ -1076,16 +1076,16 @@ extension TGFloatLayout let minSpace = lsc.minSpace let maxSpace = lsc.maxSpace - let rowCount = floor((selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding + minSpace) / (subviewSize + minSpace)) + let rowCount = floor((selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding + minSpace) / (subviewSize + minSpace)) if (rowCount > 1) { - vertSpace = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - subviewSize * rowCount)/(rowCount - 1) + vertSpace = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - subviewSize * rowCount)/(rowCount - 1) if _tgCGFloatGreat(vertSpace , maxSpace) { vertSpace = maxSpace - subviewSize = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - vertSpace * (rowCount - 1)) / rowCount + subviewSize = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - vertSpace * (rowCount - 1)) / rowCount } @@ -1097,22 +1097,22 @@ extension TGFloatLayout var topCandidateRects:[CGRect] = [CGRect]() //为了计算方便总是把最上边的个虚拟区域作为一个候选区域 - topCandidateRects.append(CGRect(x: lsc.tg_leadingPadding, y: lsc.tg_topPadding,width: CGFloat.greatestFiniteMagnitude,height: 0)) + topCandidateRects.append(CGRect(x: lsc.tgLeadingPadding, y: lsc.tgTopPadding,width: CGFloat.greatestFiniteMagnitude,height: 0)) //右边候选区域数组,保存的是CGRect值。 var bottomCandidateRects:[CGRect] = [CGRect]() //为了计算方便总是把最下边的个虚拟区域作为一个候选区域 - bottomCandidateRects.append(CGRect(x: lsc.tg_leadingPadding, y: selfSize.height - lsc.tg_bottomPadding,width: CGFloat.greatestFiniteMagnitude, height: 0)) + bottomCandidateRects.append(CGRect(x: lsc.tgLeadingPadding, y: selfSize.height - lsc.tgBottomPadding,width: CGFloat.greatestFiniteMagnitude, height: 0)) //分别记录上边和下边的最后一个视图在X轴的偏移量 - var topLastXOffset = lsc.tg_leadingPadding; - var bottomLastXOffset = lsc.tg_leadingPadding; + var topLastXOffset = lsc.tgLeadingPadding; + var bottomLastXOffset = lsc.tgLeadingPadding; //分别记录上下边和全局浮动视图的最宽占用的X轴的值 - var topMaxWidth = lsc.tg_leadingPadding - var bottomMaxWidth = lsc.tg_leadingPadding - var maxWidth = lsc.tg_leadingPadding - var maxHeight = lsc.tg_topPadding + var topMaxWidth = lsc.tgLeadingPadding + var bottomMaxWidth = lsc.tgLeadingPadding + var maxWidth = lsc.tgLeadingPadding + var maxHeight = lsc.tgTopPadding for sbv in sbs { @@ -1137,17 +1137,17 @@ extension TGFloatLayout if sbvsc.height.isRelaSizeEqualTo(lsc.height) { - rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) } if sbvsc.width.isRelaSizeEqualTo(lsc.width) && !lsc.width.isWrap { - rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) } if isWidthWeight && !lsc.width.isWrap { - rect.size.width = sbvsc.width.measure((selfSize.width - maxWidth - lsc.tg_trailingPadding) * (sbvsc.width.isFill ? 1.0 : sbvsc.width.weightVal.rawValue/100) - leadingSpace - trailingSpace) + rect.size.width = sbvsc.width.measure((selfSize.width - maxWidth - lsc.tgTrailingPadding) * (sbvsc.width.isFill ? 1.0 : sbvsc.width.weightVal.rawValue/100) - leadingSpace - trailingSpace) } @@ -1191,13 +1191,13 @@ extension TGFloatLayout assert(hasBoundaryLimit, "Constraint exception!!, horizontal float layout:\(self) can not set tg_noBoundaryLimit to true when the subview:\(sbv) set tg_reverseFloat to true.") #endif - var nextPoint = CGPoint(x: topLastXOffset, y: selfSize.height - lsc.tg_bottomPadding) - var topCandidateYBoundary = lsc.tg_topPadding; + var nextPoint = CGPoint(x: topLastXOffset, y: selfSize.height - lsc.tgBottomPadding) + var topCandidateYBoundary = lsc.tgTopPadding; if (sbvsc.tg_clearFloat) { //找到最底部的位置。 nextPoint.x = max(bottomMaxWidth, topLastXOffset); - let topPoint = self.tgFindTopCandidatePoint(CGRect(x: nextPoint.x, y: selfSize.height - lsc.tg_bottomPadding, width: CGFloat.greatestFiniteMagnitude, height: 0), height:topSpace + (isHeightWeight ? 0 : rect.size.height) + bottomSpace,topBoundary:topCandidateYBoundary,topCandidateRects:topCandidateRects,hasWeight:isHeightWeight,lsc:lsc) + let topPoint = self.tgFindTopCandidatePoint(CGRect(x: nextPoint.x, y: selfSize.height - lsc.tgBottomPadding, width: CGFloat.greatestFiniteMagnitude, height: 0), height:topSpace + (isHeightWeight ? 0 : rect.size.height) + bottomSpace,topBoundary:topCandidateYBoundary,topCandidateRects:topCandidateRects,hasWeight:isHeightWeight,lsc:lsc) if (topPoint.x != CGFloat.greatestFiniteMagnitude) { nextPoint.x = max(bottomMaxWidth, topPoint.x); @@ -1211,7 +1211,7 @@ extension TGFloatLayout while i >= 0 { let candidateRect = bottomCandidateRects[i] - let topPoint = self.tgFindTopCandidatePoint(candidateRect,height:topSpace + (isHeightWeight ? 0 : rect.size.height) + bottomSpace,topBoundary:lsc.tg_topPadding,topCandidateRects:topCandidateRects,hasWeight:isHeightWeight,lsc:lsc) + let topPoint = self.tgFindTopCandidatePoint(candidateRect,height:topSpace + (isHeightWeight ? 0 : rect.size.height) + bottomSpace,topBoundary:lsc.tgTopPadding,topCandidateRects:topCandidateRects,hasWeight:isHeightWeight,lsc:lsc) if (topPoint.x != CGFloat.greatestFiniteMagnitude) { nextPoint = CGPoint(x: max(nextPoint.x, topPoint.x),y: candidateRect.minY); @@ -1261,12 +1261,12 @@ extension TGFloatLayout sbvl.tg_leadingBorderline = nil; //如果自己的上边和左边有子视图。 - if _tgCGFloatLess(rect.origin.x + rect.size.width + trailingSpace , selfSize.width - lsc.tg_trailingPadding) + if _tgCGFloatLess(rect.origin.x + rect.size.width + trailingSpace , selfSize.width - lsc.tgTrailingPadding) { sbvl.tg_trailingBorderline = self.tg_intelligentBorderline; } - if _tgCGFloatLess(rect.origin.y + rect.size.height + bottomSpace , selfSize.height - lsc.tg_bottomPadding) + if _tgCGFloatLess(rect.origin.y + rect.size.height + bottomSpace , selfSize.height - lsc.tgBottomPadding) { sbvl.tg_bottomBorderline = self.tg_intelligentBorderline; } @@ -1282,7 +1282,7 @@ extension TGFloatLayout //这里有可能子视图本身的宽度会超过布局视图本身,但是我们的候选区域则不存储超过的宽度部分。 - var cRect = CGRect(x: rect.origin.x - leadingSpace, y: max(rect.origin.y - topSpace - vertSpace, lsc.tg_topPadding), width: rect.size.width + leadingSpace + trailingSpace + horzSpace, height: min((rect.size.height + topSpace + bottomSpace),(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding))); + var cRect = CGRect(x: rect.origin.x - leadingSpace, y: max(rect.origin.y - topSpace - vertSpace, lsc.tgTopPadding), width: rect.size.width + leadingSpace + trailingSpace + horzSpace, height: min((rect.size.height + topSpace + bottomSpace),(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding))); //把新的候选区域添加到数组中去。并删除高度小于新候选区域的其他区域 bottomCandidateRects = bottomCandidateRects.filter({_tgCGFloatGreat($0.maxX , cRect.maxX)}) @@ -1322,15 +1322,15 @@ extension TGFloatLayout } else { - var nextPoint = CGPoint(x: bottomLastXOffset,y: lsc.tg_topPadding); - var bottomCandidateYBoundary = selfSize.height - lsc.tg_bottomPadding; + var nextPoint = CGPoint(x: bottomLastXOffset,y: lsc.tgTopPadding); + var bottomCandidateYBoundary = selfSize.height - lsc.tgBottomPadding; //如果是清除了浮动则直换行移动到最下面。 if (sbvsc.tg_clearFloat) { //找到最低点。 nextPoint.x = max(topMaxWidth, bottomLastXOffset); - let bottomPoint = self.tgFindBottomCandidatePoint(CGRect(x: nextPoint.x, y: lsc.tg_topPadding,width: CGFloat.greatestFiniteMagnitude,height: 0),height:topSpace + (isHeightWeight ? 0: rect.size.height) + bottomSpace,bottomBoundary:bottomCandidateYBoundary,bottomCandidateRects:bottomCandidateRects,hasWeight:isHeightWeight,lsc:lsc) + let bottomPoint = self.tgFindBottomCandidatePoint(CGRect(x: nextPoint.x, y: lsc.tgTopPadding,width: CGFloat.greatestFiniteMagnitude,height: 0),height:topSpace + (isHeightWeight ? 0: rect.size.height) + bottomSpace,bottomBoundary:bottomCandidateYBoundary,bottomCandidateRects:bottomCandidateRects,hasWeight:isHeightWeight,lsc:lsc) if (bottomPoint.x != CGFloat.greatestFiniteMagnitude) { nextPoint.x = max(topMaxWidth, bottomPoint.x); @@ -1345,7 +1345,7 @@ extension TGFloatLayout while i >= 0 { let candidateRect = topCandidateRects[i] - let bottomPoint = self.tgFindBottomCandidatePoint(candidateRect,height:topSpace + (isHeightWeight ? 0: rect.size.height) + bottomSpace, bottomBoundary:selfSize.height - lsc.tg_bottomPadding,bottomCandidateRects:bottomCandidateRects, hasWeight:isHeightWeight,lsc:lsc); + let bottomPoint = self.tgFindBottomCandidatePoint(candidateRect,height:topSpace + (isHeightWeight ? 0: rect.size.height) + bottomSpace, bottomBoundary:selfSize.height - lsc.tgBottomPadding,bottomCandidateRects:bottomCandidateRects, hasWeight:isHeightWeight,lsc:lsc); if (bottomPoint.x != CGFloat.greatestFiniteMagnitude) { nextPoint = CGPoint(x: max(nextPoint.x, bottomPoint.x),y: candidateRect.maxY); @@ -1399,12 +1399,12 @@ extension TGFloatLayout sbvl.tg_leadingBorderline = nil; //如果自己的上边和左边有子视图。 - if _tgCGFloatGreat(rect.origin.x - leadingSpace , lsc.tg_leadingPadding) + if _tgCGFloatGreat(rect.origin.x - leadingSpace , lsc.tgLeadingPadding) { sbvl.tg_leadingBorderline = self.tg_intelligentBorderline; } - if _tgCGFloatGreat(rect.origin.y - topSpace , lsc.tg_topPadding) + if _tgCGFloatGreat(rect.origin.y - topSpace , lsc.tgTopPadding) { sbvl.tg_topBorderline = self.tg_intelligentBorderline; } @@ -1414,7 +1414,7 @@ extension TGFloatLayout } - var cRect = CGRect(x: rect.origin.x - leadingSpace, y: rect.origin.y - topSpace,width: rect.size.width + leadingSpace + trailingSpace + horzSpace,height: min((rect.size.height + topSpace + bottomSpace + vertSpace),(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding))); + var cRect = CGRect(x: rect.origin.x - leadingSpace, y: rect.origin.y - topSpace,width: rect.size.width + leadingSpace + trailingSpace + horzSpace,height: min((rect.size.height + topSpace + bottomSpace + vertSpace),(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding))); //把新添加到候选中去。并删除宽度小于的最新候选区域的候选区域 @@ -1478,8 +1478,8 @@ extension TGFloatLayout maxHeight -= vertSpace } - maxWidth += lsc.tg_trailingPadding; - maxHeight += lsc.tg_bottomPadding; + maxWidth += lsc.tgTrailingPadding; + maxHeight += lsc.tgBottomPadding; if !hasBoundaryLimit { diff --git a/TangramKit/TGFlowLayout.swift b/TangramKit/TGFlowLayout.swift index b6ab1fc..1399c47 100644 --- a/TangramKit/TGFlowLayout.swift +++ b/TangramKit/TGFlowLayout.swift @@ -289,7 +289,7 @@ open class TGFlowLayout:TGBaseLayout,TGFlowLayoutViewSizeClass { if sbvsc.width.isWrap { - if ((lsc.tg_orientation == .horz && (lsc.tg_arrangedGravity & TGGravity.vert.mask) == TGGravity.horz.fill) || + 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))) { sbvsc.width.resetValue() @@ -298,7 +298,7 @@ open class TGFlowLayout:TGBaseLayout,TGFlowLayoutViewSizeClass { if sbvsc.height.isWrap { - if ((lsc.tg_orientation == .vert && (lsc.tg_arrangedGravity & TGGravity.horz.mask) == TGGravity.vert.fill) || + 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))) { sbvsc.height.resetValue() @@ -312,7 +312,7 @@ open class TGFlowLayout:TGBaseLayout,TGFlowLayoutViewSizeClass { _ = sbvl.tg_sizeThatFits(sbvtgFrame.frame.size,inSizeClass:type) if sbvtgFrame.multiple { - sbvtgFrame.sizeClass = sbv.tgMatchBestSizeClass(type) //因为estimateLayoutRect执行后会还原,所以这里要重新设置 + sbvtgFrame.sizeClass = sbv.tgMatchBestSizeClass(type) //因为tg_sizeThatFits执行后会还原,所以这里要重新设置 } } } @@ -341,14 +341,14 @@ open class TGFlowLayout:TGBaseLayout,TGFlowLayoutViewSizeClass { //暂时把宽度存放sbvtgFrame.trailing上。因为浮动布局来说这个属性无用。 sbvtgFrame.trailing = leadingSpace + rect.size.width + trailingSpace; - if _tgCGFloatGreat(sbvtgFrame.trailing , selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + if _tgCGFloatGreat(sbvtgFrame.trailing , selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) { - sbvtgFrame.trailing = selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding; + sbvtgFrame.trailing = selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding; } } let tempSbs:NSMutableArray = NSMutableArray(array: sbs) - sbs = self.tgGetAutoArrangeSubviews(tempSbs, selfSize:selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding, space: lsc.tg_hspace) as! [UIView] + sbs = self.tgGetAutoArrangeSubviews(tempSbs, selfSize:selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding, space: lsc.tg_hspace) as! [UIView] } @@ -402,14 +402,14 @@ open class TGFlowLayout:TGBaseLayout,TGFlowLayoutViewSizeClass { //暂时把宽度存放sbvtgFrame.trailing上。因为浮动布局来说这个属性无用。 sbvtgFrame.trailing = topSpace + rect.size.height + bottomSpace; - if _tgCGFloatGreat(sbvtgFrame.trailing, selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + if _tgCGFloatGreat(sbvtgFrame.trailing, selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) { - sbvtgFrame.trailing = selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding; + sbvtgFrame.trailing = selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding; } } let tempSbs:NSMutableArray = NSMutableArray(array: sbs) - sbs = self.tgGetAutoArrangeSubviews(tempSbs, selfSize:selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding, space: lsc.tg_vspace) as! [UIView] + sbs = self.tgGetAutoArrangeSubviews(tempSbs, selfSize:selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding, space: lsc.tg_vspace) as! [UIView] } @@ -552,16 +552,16 @@ extension TGFlowLayout if !averageArrange || lsc.tg_arrangedCount == 0 { switch horzGravity { case TGGravity.horz.center: - addXPos = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - rowMaxWidth)/2 + addXPos = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - rowMaxWidth)/2 break case TGGravity.horz.trailing: //不用考虑左边距,而原来的位置增加了左边距 因此不用考虑 - addXPos = selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - rowMaxWidth + addXPos = selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - rowMaxWidth break case TGGravity.horz.between: //总宽减去最大的宽度,再除以数量表示每个应该扩展的空间,对最后一行无效 if (startIndex != sbs.count || count == lsc.tg_arrangedCount) && count > 1 { - addXFill = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - rowMaxWidth)/(CGFloat(count) - 1) + addXFill = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - rowMaxWidth)/(CGFloat(count) - 1) } break default: @@ -570,7 +570,7 @@ extension TGFlowLayout //处理内容拉伸的情况 if lsc.tg_arrangedCount == 0 && averageArrange { if startIndex != sbs.count { - addXFill = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - rowMaxWidth)/CGFloat(count) + addXFill = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - rowMaxWidth)/CGFloat(count) } } } @@ -683,15 +683,15 @@ extension TGFlowLayout if !averageArrange || lsc.tg_arrangedCount == 0 { switch vertGravity { case TGGravity.vert.center: - addYPos = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - colMaxHeight)/2 + addYPos = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - colMaxHeight)/2 break case TGGravity.vert.bottom: - addYPos = selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - colMaxHeight + addYPos = selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - colMaxHeight break case TGGravity.vert.between: //总高减去最大高度,再除以数量表示每个应该扩展的空气,最后一列无效 if (startIndex != sbs.count || count == lsc.tg_arrangedCount) && count > 1 { - addYFill = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - colMaxHeight)/(CGFloat(count) - 1) + addYFill = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - colMaxHeight)/(CGFloat(count) - 1) } break default: @@ -701,7 +701,7 @@ extension TGFlowLayout //处理内容拉伸的情况 if lsc.tg_arrangedCount == 0 && averageArrange { if startIndex != sbs.count { - addYFill = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - colMaxHeight)/CGFloat(count) + addYFill = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - colMaxHeight)/CGFloat(count) } } } @@ -852,11 +852,11 @@ extension TGFlowLayout fileprivate func tgLayoutSubviewsForVert(_ selfSize:CGSize, sbs:[UIView], isEstimate:Bool, lsc:TGFlowLayoutViewSizeClassImpl)->CGSize { var selfSize = selfSize let arrangedCount:Int = lsc.tg_arrangedCount - var xPos:CGFloat = lsc.tg_leadingPadding - var yPos:CGFloat = lsc.tg_topPadding + var xPos:CGFloat = lsc.tgLeadingPadding + var yPos:CGFloat = lsc.tgTopPadding var rowMaxHeight:CGFloat = 0 var rowMaxWidth:CGFloat = 0 - var maxWidth = lsc.tg_leadingPadding + var maxWidth = lsc.tgLeadingPadding let vertGravity:TGGravity = lsc.tg_gravity & TGGravity.horz.mask let horzGravity:TGGravity = self.tgConvertLeftRightGravityToLeadingTrailing(lsc.tg_gravity & TGGravity.vert.mask) @@ -887,27 +887,27 @@ extension TGFlowLayout isHorzPaging = true if isPagingScroll { - pagingItemWidth = (self.superview!.bounds.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - CGFloat(arrangedCount - 1) * horzSpace ) / CGFloat(arrangedCount) + pagingItemWidth = (self.superview!.bounds.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - CGFloat(arrangedCount - 1) * horzSpace ) / CGFloat(arrangedCount) } else { - pagingItemWidth = (self.superview!.bounds.width - lsc.tg_leadingPadding - CGFloat(arrangedCount) * horzSpace ) / CGFloat(arrangedCount) + pagingItemWidth = (self.superview!.bounds.width - lsc.tgLeadingPadding - CGFloat(arrangedCount) * horzSpace ) / CGFloat(arrangedCount) } - pagingItemHeight = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - (rows - 1) * vertSpace) / rows + pagingItemHeight = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - (rows - 1) * vertSpace) / rows } else { isVertPaging = true - pagingItemWidth = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - CGFloat(arrangedCount - 1) * horzSpace) / CGFloat(arrangedCount) + pagingItemWidth = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - CGFloat(arrangedCount - 1) * horzSpace) / CGFloat(arrangedCount) //分页滚动时和非分页滚动时的高度计算是不一样的。 if (isPagingScroll) { - pagingItemHeight = (self.superview!.bounds.height - lsc.tg_topPadding - lsc.tg_bottomPadding - (rows - 1) * vertSpace) / CGFloat(rows) + pagingItemHeight = (self.superview!.bounds.height - lsc.tgTopPadding - lsc.tgBottomPadding - (rows - 1) * vertSpace) / CGFloat(rows) } else { - pagingItemHeight = (self.superview!.bounds.height - lsc.tg_topPadding - rows * vertSpace) / rows + pagingItemHeight = (self.superview!.bounds.height - lsc.tgTopPadding - rows * vertSpace) / rows } } @@ -932,7 +932,7 @@ extension TGFlowLayout if (rowTotalWeight != 0 && !averageArrange) { - self.tgCalcVertLayoutSinglelineWeight(selfSize:selfSize,totalFloatWidth:selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - rowTotalFixedWidth,totalWeight:rowTotalWeight,sbs:sbs,startIndex:i,count:arrangedCount) + self.tgCalcVertLayoutSinglelineWeight(selfSize:selfSize,totalFloatWidth:selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - rowTotalFixedWidth,totalWeight:rowTotalWeight,sbs:sbs,startIndex:i,count:arrangedCount) } rowTotalWeight = 0; @@ -997,12 +997,12 @@ extension TGFlowLayout rowTotalFixedWidth -= horzSpace } - self.tgCalcVertLayoutSinglelineWeight(selfSize:selfSize,totalFloatWidth:selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - rowTotalFixedWidth,totalWeight:rowTotalWeight,sbs:sbs,startIndex:sbs.count, count:arrangedIndex) + self.tgCalcVertLayoutSinglelineWeight(selfSize:selfSize,totalFloatWidth:selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - rowTotalFixedWidth,totalWeight:rowTotalWeight,sbs:sbs,startIndex:sbs.count, count:arrangedIndex) } var pageWidth:CGFloat = 0; //页宽 - let averageWidth:CGFloat = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - (CGFloat(arrangedCount) - 1) * horzSpace) / CGFloat(arrangedCount) + let averageWidth:CGFloat = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - (CGFloat(arrangedCount) - 1) * horzSpace) / CGFloat(arrangedCount) arrangedIndex = 0 for i in 0.. 0) { - fill = (selfSize.height - lsc.tg_bottomPadding - rowMaxHeight - yPos) / arranges + fill = (selfSize.height - lsc.tgBottomPadding - rowMaxHeight - yPos) / arranges } } else if (vertGravity == TGGravity.vert.between) @@ -1169,7 +1169,7 @@ extension TGFlowLayout if (arranges > 1) { - between = (selfSize.height - lsc.tg_bottomPadding - rowMaxHeight - yPos) / (arranges - 1) + between = (selfSize.height - lsc.tgBottomPadding - rowMaxHeight - yPos) / (arranges - 1) } } @@ -1192,7 +1192,7 @@ extension TGFlowLayout if lsc.width.isWrap && !averageArrange { - selfSize.width = maxWidth + lsc.tg_trailingPadding + selfSize.width = maxWidth + lsc.tgTrailingPadding //只有在父视图为滚动视图,且开启了分页滚动时才会扩充具有包裹设置的布局视图的宽度。 if (isHorzPaging && isPagingScroll) @@ -1213,8 +1213,8 @@ extension TGFlowLayout fileprivate func tgLayoutSubviewsForVertContent(_ selfSize:CGSize, sbs:[UIView], isEstimate:Bool, lsc:TGFlowLayoutViewSizeClassImpl)->CGSize { var selfSize = selfSize - var xPos:CGFloat = lsc.tg_leadingPadding - var yPos:CGFloat = lsc.tg_topPadding + var xPos:CGFloat = lsc.tgLeadingPadding + var yPos:CGFloat = lsc.tgTopPadding var rowMaxHeight:CGFloat = 0 var rowMaxWidth:CGFloat = 0 @@ -1232,16 +1232,16 @@ extension TGFlowLayout let maxSpace = lsc.maxSpace - let rowCount = floor((selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding + minSpace) / (subviewSize + minSpace)) + let rowCount = floor((selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding + minSpace) / (subviewSize + minSpace)) if (rowCount > 1) { - horzSpace = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - subviewSize * rowCount)/(rowCount - 1) + horzSpace = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - subviewSize * rowCount)/(rowCount - 1) if _tgCGFloatGreat(horzSpace , maxSpace) { horzSpace = maxSpace - subviewSize = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - horzSpace * (rowCount - 1)) / rowCount; + subviewSize = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - horzSpace * (rowCount - 1)) / rowCount; } } @@ -1279,13 +1279,13 @@ extension TGFlowLayout heightWeight = t.rawValue/100 } - rect.size.height = sbv.tg_height.measure((selfSize.height - yPos - lsc.tg_bottomPadding)*heightWeight - topSpace - bottomSpace) + rect.size.height = sbv.tg_height.measure((selfSize.height - yPos - lsc.tgBottomPadding)*heightWeight - topSpace - bottomSpace) } if sbvsc.width.weightVal != nil || sbvsc.width.isFill { //如果过了,则表示当前的剩余空间为0了,所以就按新的一行来算。。 - var floatWidth = selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - rowMaxWidth; + var floatWidth = selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - rowMaxWidth; if _tgCGFloatLessOrEqual(floatWidth, 0) { floatWidth += rowMaxWidth @@ -1328,12 +1328,12 @@ extension TGFlowLayout if arrangeIndex != 0 { place += horzSpace } - place += lsc.tg_trailingPadding + place += lsc.tgTrailingPadding //sbv所占据的宽度要超过了视图的整体宽度,因此需要换行。但是如果arrangedIndex为0的话表示这个控件的整行的宽度和布局视图保持一致。 if place - selfSize.width > 0.0001 { - xPos = lsc.tg_leadingPadding + xPos = lsc.tgLeadingPadding yPos += vertSpace yPos += rowMaxHeight @@ -1342,9 +1342,9 @@ extension TGFlowLayout self .tgCalcVertLayoutSinglelineAlignment(selfSize, rowMaxHeight: rowMaxHeight, rowMaxWidth: rowMaxWidth, horzGravity: horzGravity, vertAlignment: vertAlignment, sbs: sbs, startIndex: i, count: arrangeIndex, vertSpace: vertSpace, horzSpace: horzSpace, isEstimate: isEstimate, lsc:lsc) //计算单独的sbv的宽度是否大于整体的宽度。如果大于则缩小宽度。 - if _tgCGFloatGreat(leadingSpace + trailingSpace + rect.size.width , selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + if _tgCGFloatGreat(leadingSpace + trailingSpace + rect.size.width , selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) { - rect.size.width = self.tgValidMeasure(sbvsc.width, sbv: sbv, calcSize: selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - leadingSpace - trailingSpace, sbvSize: rect.size, selfLayoutSize: selfSize) + rect.size.width = self.tgValidMeasure(sbvsc.width, sbv: sbv, calcSize: selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - leadingSpace - trailingSpace, sbvSize: rect.size, selfLayoutSize: selfSize) if sbvsc.height.isFlexHeight { @@ -1370,8 +1370,8 @@ extension TGFlowLayout if _tgCGFloatLess(rowMaxHeight , topSpace + bottomSpace + rect.size.height) { rowMaxHeight = topSpace + bottomSpace + rect.size.height; } - if _tgCGFloatLess(rowMaxWidth , xPos - lsc.tg_leadingPadding) { - rowMaxWidth = xPos - lsc.tg_leadingPadding + if _tgCGFloatLess(rowMaxWidth , xPos - lsc.tgLeadingPadding) { + rowMaxWidth = xPos - lsc.tgLeadingPadding } sbvtgFrame.frame = rect; @@ -1383,7 +1383,7 @@ extension TGFlowLayout self .tgCalcVertLayoutSinglelineAlignment(selfSize, rowMaxHeight: rowMaxHeight, rowMaxWidth: rowMaxWidth, horzGravity: horzGravity, vertAlignment: vertAlignment, sbs: sbs, startIndex:sbs.count, count: arrangeIndex, vertSpace: vertSpace, horzSpace: horzSpace,isEstimate: isEstimate, lsc:lsc) if lsc.height.isWrap { - selfSize.height = yPos + lsc.tg_bottomPadding + rowMaxHeight; + selfSize.height = yPos + lsc.tgBottomPadding + rowMaxHeight; } else { var addYPos:CGFloat = 0 @@ -1391,23 +1391,23 @@ extension TGFlowLayout var fill:CGFloat = 0 if vertGravity == TGGravity.vert.center { - addYPos = (selfSize.height - lsc.tg_bottomPadding - rowMaxHeight - yPos)/2 + addYPos = (selfSize.height - lsc.tgBottomPadding - rowMaxHeight - yPos)/2 } else if vertGravity == TGGravity.vert.bottom { - addYPos = selfSize.height - lsc.tg_bottomPadding - rowMaxHeight - yPos + addYPos = selfSize.height - lsc.tgBottomPadding - rowMaxHeight - yPos } else if vertGravity == TGGravity.vert.fill { if arrangeIndexSet.count > 0 { - fill = (selfSize.height - lsc.tg_bottomPadding - rowMaxHeight - yPos) / CGFloat(arrangeIndexSet.count) + fill = (selfSize.height - lsc.tgBottomPadding - rowMaxHeight - yPos) / CGFloat(arrangeIndexSet.count) } } else if (vertGravity == TGGravity.vert.between) { if arrangeIndexSet.count > 1 { - between = (selfSize.height - lsc.tg_bottomPadding - rowMaxHeight - yPos) / CGFloat(arrangeIndexSet.count - 1) + between = (selfSize.height - lsc.tgBottomPadding - rowMaxHeight - yPos) / CGFloat(arrangeIndexSet.count - 1) } } @@ -1443,11 +1443,11 @@ extension TGFlowLayout fileprivate func tgLayoutSubviewsForHorz(_ selfSize:CGSize, sbs:[UIView], isEstimate:Bool, lsc:TGFlowLayoutViewSizeClassImpl)->CGSize { let arrangedCount:Int = lsc.tg_arrangedCount - var xPos:CGFloat = lsc.tg_leadingPadding - var yPos:CGFloat = lsc.tg_topPadding + var xPos:CGFloat = lsc.tgLeadingPadding + var yPos:CGFloat = lsc.tgTopPadding var colMaxWidth:CGFloat = 0 var colMaxHeight:CGFloat = 0 - var maxHeight:CGFloat = lsc.tg_topPadding + var maxHeight:CGFloat = lsc.tgTopPadding var selfSize = selfSize let vertGravity:TGGravity = lsc.tg_gravity & TGGravity.horz.mask @@ -1479,27 +1479,27 @@ extension TGFlowLayout isVertPaging = true if isPagingScroll { - pagingItemHeight = (self.superview!.bounds.height - lsc.tg_topPadding - lsc.tg_bottomPadding - CGFloat(arrangedCount - 1) * vertSpace ) / CGFloat(arrangedCount) + pagingItemHeight = (self.superview!.bounds.height - lsc.tgTopPadding - lsc.tgBottomPadding - CGFloat(arrangedCount - 1) * vertSpace ) / CGFloat(arrangedCount) } else { - pagingItemHeight = (self.superview!.bounds.height - lsc.tg_topPadding - CGFloat(arrangedCount) * vertSpace ) / CGFloat(arrangedCount) + pagingItemHeight = (self.superview!.bounds.height - lsc.tgTopPadding - CGFloat(arrangedCount) * vertSpace ) / CGFloat(arrangedCount) } - pagingItemWidth = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - (cols - 1) * horzSpace) / cols + pagingItemWidth = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - (cols - 1) * horzSpace) / cols } else { isHorzPaging = true - pagingItemHeight = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - CGFloat(arrangedCount - 1) * vertSpace) / CGFloat(arrangedCount) + pagingItemHeight = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - CGFloat(arrangedCount - 1) * vertSpace) / CGFloat(arrangedCount) //分页滚动时和非分页滚动时的高度计算是不一样的。 if (isPagingScroll) { - pagingItemWidth = (self.superview!.bounds.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - (cols - 1) * horzSpace) / cols + pagingItemWidth = (self.superview!.bounds.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - (cols - 1) * horzSpace) / cols } else { - pagingItemWidth = (self.superview!.bounds.width - lsc.tg_leadingPadding - cols * horzSpace) / cols + pagingItemWidth = (self.superview!.bounds.width - lsc.tgLeadingPadding - cols * horzSpace) / cols } } @@ -1523,7 +1523,7 @@ extension TGFlowLayout if (rowTotalWeight != 0 && !averageArrange) { - self.tgCalcHorzLayoutSinglelineWeight(selfSize:selfSize,totalFloatHeight:selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - rowTotalFixedHeight,totalWeight:rowTotalWeight,sbs:sbs,startIndex:i,count:arrangedCount) + self.tgCalcHorzLayoutSinglelineWeight(selfSize:selfSize,totalFloatHeight:selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - rowTotalFixedHeight,totalWeight:rowTotalWeight,sbs:sbs,startIndex:i,count:arrangedCount) } rowTotalWeight = 0; @@ -1614,12 +1614,12 @@ extension TGFlowLayout rowTotalFixedHeight -= vertSpace } - self.tgCalcHorzLayoutSinglelineWeight(selfSize:selfSize,totalFloatHeight:selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - rowTotalFixedHeight,totalWeight:rowTotalWeight,sbs:sbs,startIndex:sbs.count,count:arrangedIndex) + self.tgCalcHorzLayoutSinglelineWeight(selfSize:selfSize,totalFloatHeight:selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - rowTotalFixedHeight,totalWeight:rowTotalWeight,sbs:sbs,startIndex:sbs.count,count:arrangedIndex) } var pageHeight:CGFloat = 0 - let averageHeight:CGFloat = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - (CGFloat(arrangedCount) - 1) * vertSpace) / CGFloat(arrangedCount) + let averageHeight:CGFloat = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - (CGFloat(arrangedCount) - 1) * vertSpace) / CGFloat(arrangedCount) arrangedIndex = 0 for i in 0.. 0) { - fill = (selfSize.width - lsc.tg_trailingPadding - colMaxWidth - xPos) / arranges + fill = (selfSize.width - lsc.tgTrailingPadding - colMaxWidth - xPos) / arranges } } else if (horzGravity == TGGravity.horz.between) { if (arranges > 1) { - between = (selfSize.width - lsc.tg_leadingPadding - colMaxWidth - xPos) / (arranges - 1) + between = (selfSize.width - lsc.tgLeadingPadding - colMaxWidth - xPos) / (arranges - 1) } } @@ -1818,8 +1818,8 @@ extension TGFlowLayout } fileprivate func tgLayoutSubviewsForHorzContent(_ selfSize:CGSize, sbs:[UIView], isEstimate:Bool, lsc:TGFlowLayoutViewSizeClassImpl)->CGSize { - var xPos:CGFloat = lsc.tg_leadingPadding - var yPos:CGFloat = lsc.tg_topPadding + var xPos:CGFloat = lsc.tgLeadingPadding + var yPos:CGFloat = lsc.tgTopPadding var colMaxWidth:CGFloat = 0 var colMaxHeight:CGFloat = 0 @@ -1839,16 +1839,16 @@ extension TGFlowLayout let minSpace = lsc.minSpace let maxSpace = lsc.maxSpace - let rowCount = floor((selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding + minSpace) / (subviewSize + minSpace)) + let rowCount = floor((selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding + minSpace) / (subviewSize + minSpace)) if (rowCount > 1) { - vertSpace = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - subviewSize * rowCount)/(rowCount - 1) + vertSpace = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - subviewSize * rowCount)/(rowCount - 1) if _tgCGFloatGreat(vertSpace , maxSpace) { vertSpace = maxSpace - subviewSize = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - vertSpace * (rowCount - 1)) / rowCount + subviewSize = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - vertSpace * (rowCount - 1)) / rowCount } @@ -1886,7 +1886,7 @@ extension TGFlowLayout if sbvsc.height.weightVal != nil || sbvsc.height.isFill { //如果过了,则表示当前的剩余空间为0了,所以就按新的一行来算。。 - var floatHeight = selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - colMaxHeight; + var floatHeight = selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - colMaxHeight; if (_tgCGFloatLessOrEqual(floatHeight, 0)) { floatHeight += colMaxHeight; @@ -1925,7 +1925,7 @@ extension TGFlowLayout widthWeight = t.rawValue / 100 } - rect.size.width = sbvsc.width.measure((selfSize.width - xPos - lsc.tg_trailingPadding)*widthWeight - leadingSpace - trailingSpace) + rect.size.width = sbvsc.width.measure((selfSize.width - xPos - lsc.tgTrailingPadding)*widthWeight - leadingSpace - trailingSpace) } @@ -1946,12 +1946,12 @@ extension TGFlowLayout if arrangedIndex != 0 { place += vertSpace } - place += lsc.tg_bottomPadding + place += lsc.tgBottomPadding //sbv所占据的宽度要超过了视图的整体宽度,因此需要换行。但是如果arrangedIndex为0的话表示这个控件的整行的宽度和布局视图保持一致。 if place - selfSize.height > 0.0001 { - yPos = lsc.tg_topPadding + yPos = lsc.tgTopPadding xPos += horzSpace xPos += colMaxWidth @@ -1960,9 +1960,9 @@ extension TGFlowLayout self.tgCalcHorzLayoutSinglelineAlignment(selfSize, colMaxHeight: colMaxHeight, colMaxWidth: colMaxWidth, vertGravity: vertGravity, horzAlignment: horzAlignment, sbs: sbs, startIndex: i, count: arrangedIndex, vertSpace: vertSpace, horzSpace: horzSpace, isEstimate: isEstimate, lsc:lsc) //计算单独的sbv的高度是否大于整体的高度。如果大于则缩小高度。 - if _tgCGFloatGreat(topSpace + bottomSpace + rect.size.height , selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + if _tgCGFloatGreat(topSpace + bottomSpace + rect.size.height , selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) { - rect.size.height = selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - topSpace - bottomSpace + rect.size.height = selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - topSpace - bottomSpace rect.size.height = self.tgValidMeasure(sbvsc.height, sbv: sbv, calcSize: rect.size.height, sbvSize: rect.size, selfLayoutSize: selfSize) } @@ -1983,9 +1983,9 @@ extension TGFlowLayout colMaxWidth = leadingSpace + trailingSpace + rect.size.width } - if _tgCGFloatLess(colMaxHeight , (yPos - lsc.tg_topPadding)) + if _tgCGFloatLess(colMaxHeight , (yPos - lsc.tgTopPadding)) { - colMaxHeight = (yPos - lsc.tg_topPadding); + colMaxHeight = (yPos - lsc.tgTopPadding); } sbvtgFrame.frame = rect; @@ -1997,7 +1997,7 @@ extension TGFlowLayout self.tgCalcHorzLayoutSinglelineAlignment(selfSize, colMaxHeight: colMaxHeight, colMaxWidth: colMaxWidth, vertGravity: vertGravity, horzAlignment: horzAlignment, sbs: sbs, startIndex: sbs.count, count: arrangedIndex, vertSpace: vertSpace, horzSpace: horzSpace,isEstimate: isEstimate, lsc:lsc) if lsc.width.isWrap { - selfSize.width = xPos + lsc.tg_trailingPadding + colMaxWidth + selfSize.width = xPos + lsc.tgTrailingPadding + colMaxWidth } else { var addXPos:CGFloat = 0 @@ -2006,24 +2006,24 @@ extension TGFlowLayout if (horzGravity == TGGravity.horz.center) { - addXPos = (selfSize.width - lsc.tg_trailingPadding - colMaxWidth - xPos) / 2; + addXPos = (selfSize.width - lsc.tgTrailingPadding - colMaxWidth - xPos) / 2; } else if (horzGravity == TGGravity.horz.trailing) { - addXPos = selfSize.width - lsc.tg_trailingPadding - colMaxWidth - xPos; + addXPos = selfSize.width - lsc.tgTrailingPadding - colMaxWidth - xPos; } else if (horzGravity == TGGravity.horz.fill) { if (arrangeIndexSet.count > 0) { - fill = (selfSize.width - lsc.tg_trailingPadding - colMaxWidth - xPos) / CGFloat(arrangeIndexSet.count) + fill = (selfSize.width - lsc.tgTrailingPadding - colMaxWidth - xPos) / CGFloat(arrangeIndexSet.count) } } else if (horzGravity == TGGravity.horz.between) { if (arrangeIndexSet.count > 1) { - between = (selfSize.width - lsc.tg_trailingPadding - colMaxWidth - xPos) / CGFloat(arrangeIndexSet.count - 1) + between = (selfSize.width - lsc.tgTrailingPadding - colMaxWidth - xPos) / CGFloat(arrangeIndexSet.count - 1) } } diff --git a/TangramKit/TGFrameLayout.swift b/TangramKit/TGFrameLayout.swift index b22d048..991b99c 100644 --- a/TangramKit/TGFrameLayout.swift +++ b/TangramKit/TGFrameLayout.swift @@ -43,7 +43,7 @@ open class TGFrameLayout: TGBaseLayout,TGFrameLayoutViewSizeClass { var maxWrapSize:CGSize! = nil if lsc.isSomeSizeWrap { - maxWrapSize = CGSize(width: lsc.tg_leadingPadding + lsc.tg_trailingPadding, height: lsc.tg_topPadding + lsc.tg_bottomPadding) + maxWrapSize = CGSize(width: lsc.tgLeadingPadding + lsc.tgTrailingPadding, height: lsc.tgTopPadding + lsc.tgBottomPadding) } for sbv in sbs @@ -160,8 +160,8 @@ extension TGFrameLayout maxWrapSize:inout CGSize!) { - let selfFloatWidth = selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - let selfFloatHeight = selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding + let selfFloatWidth = selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding + let selfFloatHeight = selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding let leadingMargin = sbvsc.leading.weightPosIn(selfFloatWidth) let trailingMargin = sbvsc.trailing.weightPosIn(selfFloatWidth) let topMargin = sbvsc.top.weightPosIn(selfFloatHeight) @@ -180,6 +180,10 @@ extension TGFrameLayout { rect.size.width = sbvsc.width.measure(selfFloatWidth) } + else if t === lsc.height.realSize + { + rect.size.width = sbvsc.width.measure(selfFloatHeight) + } else { rect.size.width = sbvsc.width.measure(t.view.tg_estimatedFrame.width) @@ -198,6 +202,10 @@ extension TGFrameLayout { rect.size.height = sbvsc.height.measure(selfFloatHeight) } + else if t === lsc.width.realSize + { + rect.size.height = sbvsc.height.measure(selfFloatWidth) + } else { rect.size.height = sbvsc.height.measure(t.view.tg_estimatedFrame.height) @@ -258,8 +266,8 @@ extension TGFrameLayout sbvSize:sbvsc.width, sbvMeasure:sbvtgFrame.width, sbvMaxPos:sbvtgFrame.trailing, - headPadding:lsc.tg_leadingPadding, - tailPadding:lsc.tg_trailingPadding, + headPadding:lsc.tgLeadingPadding, + tailPadding:lsc.tgTrailingPadding, lscSize:lsc.width, maxSize:maxWrapSize.width) @@ -269,8 +277,8 @@ extension TGFrameLayout sbvSize:sbvsc.height, sbvMeasure:sbvtgFrame.height, sbvMaxPos:sbvtgFrame.bottom, - headPadding:lsc.tg_topPadding, - tailPadding:lsc.tg_bottomPadding, + headPadding:lsc.tgTopPadding, + tailPadding:lsc.tgBottomPadding, lscSize:lsc.height, maxSize:maxWrapSize.height) } diff --git a/TangramKit/TGLayoutPos.swift b/TangramKit/TGLayoutPos.swift index 5306b90..06bb71b 100644 --- a/TangramKit/TGLayoutPos.swift +++ b/TangramKit/TGLayoutPos.swift @@ -303,6 +303,16 @@ final public class TGLayoutPos:TGLayoutPosValue case .floatV(let v): return v case .layoutSupport(let v): + //只有在11以后并且是设置了safearea缩进才忽略UILayoutSupport。 + if let superlayout = self.view.superview as? TGBaseLayout, #available(iOS 11.0, *) + { + let edge = superlayout.tg_insetsPaddingFromSafeArea.rawValue + if ((_type == TGGravity.vert.top && (edge & UIRectEdge.top.rawValue) == UIRectEdge.top.rawValue) || + (_type == TGGravity.vert.bottom && (edge & UIRectEdge.bottom.rawValue) == UIRectEdge.bottom.rawValue)) + { + return 0 + } + } return v.length default: return nil @@ -635,7 +645,7 @@ extension TGLayoutPos:NSCopying { public func copy(with zone: NSZone? = nil) -> Any { - let ls:TGLayoutPos = type(of: self).init(_type, view:_view) + let ls:TGLayoutPos = Swift.type(of: self).init(_type, view:_view) ls._active = self._active ls._val = self._val ls._offset = self._offset diff --git a/TangramKit/TGLayoutSize.swift b/TangramKit/TGLayoutSize.swift index 4b3f383..7874bd3 100644 --- a/TangramKit/TGLayoutSize.swift +++ b/TangramKit/TGLayoutSize.swift @@ -735,7 +735,7 @@ extension TGLayoutSize:NSCopying { public func copy(with zone: NSZone? = nil) -> Any { - let ls:TGLayoutSize = type(of: self).init(_type, view:_view) + let ls:TGLayoutSize = Swift.type(of: self).init(_type, view:_view) ls._active = self._active ls._val = self._val ls._increment = self._increment diff --git a/TangramKit/TGLayoutSizeClass.swift b/TangramKit/TGLayoutSizeClass.swift index 1bb9e5a..611591a 100644 --- a/TangramKit/TGLayoutSizeClass.swift +++ b/TangramKit/TGLayoutSizeClass.swift @@ -143,6 +143,8 @@ public protocol TGLayoutViewSizeClass:TGViewSizeClass var tg_bottomPadding:CGFloat{get set} var tg_trailingPadding:CGFloat{get set} var tg_zeroPadding:Bool{get set} + var tg_insetsPaddingFromSafeArea:UIRectEdge{get set} + var tg_insetLandscapeFringePadding:Bool {get set} var tg_leftPadding:CGFloat{get set} var tg_rightPadding:CGFloat{get set} @@ -571,6 +573,9 @@ internal class TGLayoutViewSizeClassImpl:TGViewSizeClassImpl,TGLayoutViewSizeCla var tg_zeroPadding: Bool = true + var tg_insetsPaddingFromSafeArea: UIRectEdge = .all + var tg_insetLandscapeFringePadding: Bool = false + var tg_vspace:CGFloat = 0 var tg_hspace:CGFloat = 0 @@ -590,15 +595,195 @@ internal class TGLayoutViewSizeClassImpl:TGViewSizeClassImpl,TGLayoutViewSizeCla var tg_reverseLayout: Bool = false var tg_gravity: TGGravity = .none + + internal var tgTopPadding:CGFloat + { + if ((self.tg_insetsPaddingFromSafeArea.rawValue & UIRectEdge.top.rawValue) == UIRectEdge.top.rawValue) + { + if #available(iOS 11.0, *) { + return self.tg_topPadding + self.view.safeAreaInsets.top + } + } + return self.tg_topPadding + + } + + internal var tgLeadingPadding:CGFloat + { + var inset:CGFloat = 0 + + if #available(iOS 11.0, *) { + + var edge:UIRectEdge + var devori:UIDeviceOrientation + if TGViewSizeClassImpl.IsRTL + { + edge = .right + devori = .landscapeLeft + } + else + { + edge = .left + devori = .landscapeRight + } + + if (self.tg_insetsPaddingFromSafeArea.rawValue & edge.rawValue) == edge.rawValue + { + //如果只缩进刘海那一边。并且同时设置了左右缩进,并且当前刘海方向是右边那么就不缩进了。 + if (self.tg_insetLandscapeFringePadding && + (self.tg_insetsPaddingFromSafeArea.rawValue & (UIRectEdge.left.rawValue | UIRectEdge.right.rawValue)) == (UIRectEdge.left.rawValue | UIRectEdge.right.rawValue) && + UIDevice.current.orientation == devori) + { + inset = 0 + } + else + { + if TGViewSizeClassImpl.IsRTL + { + inset = self.view.safeAreaInsets.right + } + else + { + inset = self.view.safeAreaInsets.left + } + } + } + } + + if TGViewSizeClassImpl.IsRTL + { + return self.tg_rightPadding + inset + } + else + { + return self.tg_leftPadding + inset + } + } + + internal var tgBottomPadding:CGFloat + { + if ((self.tg_insetsPaddingFromSafeArea.rawValue & UIRectEdge.bottom.rawValue) == UIRectEdge.bottom.rawValue) + { + if #available(iOS 11.0, *) { + return self.tg_bottomPadding + self.view.safeAreaInsets.bottom + } + } + return self.tg_bottomPadding + } + + + internal var tgTrailingPadding:CGFloat + { + var inset:CGFloat = 0 + + if #available(iOS 11.0, *) { + + var edge:UIRectEdge + var devori:UIDeviceOrientation + if TGViewSizeClassImpl.IsRTL + { + edge = .left + devori = .landscapeRight + } + else + { + edge = .right + devori = .landscapeLeft + } + + if (self.tg_insetsPaddingFromSafeArea.rawValue & edge.rawValue) == edge.rawValue + { + //如果只缩进刘海那一边。并且同时设置了左右缩进,并且当前刘海方向是右边那么就不缩进了。 + if (self.tg_insetLandscapeFringePadding && + (self.tg_insetsPaddingFromSafeArea.rawValue & (UIRectEdge.left.rawValue | UIRectEdge.right.rawValue)) == (UIRectEdge.left.rawValue | UIRectEdge.right.rawValue) && + UIDevice.current.orientation == devori) + { + inset = 0 + } + else + { + if TGViewSizeClassImpl.IsRTL + { + inset = self.view.safeAreaInsets.left + } + else + { + inset = self.view.safeAreaInsets.right + } + } + } + } + + if TGViewSizeClassImpl.IsRTL + { + return self.tg_leftPadding + inset + } + else + { + return self.tg_rightPadding + inset + } + } + + internal var tgLeftPadding:CGFloat + { + var inset:CGFloat = 0 + + if #available(iOS 11.0, *) { + if (self.tg_insetsPaddingFromSafeArea.rawValue & UIRectEdge.left.rawValue) == UIRectEdge.left.rawValue + { + //如果只缩进刘海那一边。并且同时设置了左右缩进,并且当前刘海方向是右边那么就不缩进了。 + if (self.tg_insetLandscapeFringePadding && + (self.tg_insetsPaddingFromSafeArea.rawValue & (UIRectEdge.left.rawValue | UIRectEdge.right.rawValue)) == (UIRectEdge.left.rawValue | UIRectEdge.right.rawValue) && + UIDevice.current.orientation == .landscapeRight) + { + inset = 0 + } + else + { + inset = self.view.safeAreaInsets.left + } + } + } + + return self.tg_leftPadding + inset + } + + internal var tgRightPadding:CGFloat + { + var inset:CGFloat = 0 + + if #available(iOS 11.0, *) { + if (self.tg_insetsPaddingFromSafeArea.rawValue & UIRectEdge.right.rawValue) == UIRectEdge.right.rawValue + { + //如果只缩进刘海那一边。并且同时设置了左右缩进,并且当前刘海方向是右边那么就不缩进了。 + if (self.tg_insetLandscapeFringePadding && + (self.tg_insetsPaddingFromSafeArea.rawValue & (UIRectEdge.left.rawValue | UIRectEdge.right.rawValue)) == (UIRectEdge.left.rawValue | UIRectEdge.right.rawValue) && + UIDevice.current.orientation == .landscapeLeft) + { + inset = 0 + } + else + { + inset = self.view.safeAreaInsets.right + } + } + } + + return self.tg_rightPadding + inset + } + + override func copy(with zone: NSZone?) -> Any { let tsc = super.copy(with: zone) as! TGLayoutViewSizeClassImpl - tsc.tg_topPadding = self.tg_topPadding + tsc.tg_topPadding = self.tgTopPadding tsc.tg_leadingPadding = self.tg_leadingPadding tsc.tg_bottomPadding = self.tg_bottomPadding tsc.tg_trailingPadding = self.tg_trailingPadding tsc.tg_zeroPadding = self.tg_zeroPadding + tsc.tg_insetsPaddingFromSafeArea = self.tg_insetsPaddingFromSafeArea + tsc.tg_insetLandscapeFringePadding = self.tg_insetLandscapeFringePadding tsc.tg_vspace = self.tg_vspace tsc.tg_hspace = self.tg_hspace tsc.tg_reverseLayout = self.tg_reverseLayout diff --git a/TangramKit/TGLinearLayout.swift b/TangramKit/TGLinearLayout.swift index 6e33530..ea3df57 100644 --- a/TangramKit/TGLinearLayout.swift +++ b/TangramKit/TGLinearLayout.swift @@ -288,7 +288,7 @@ open class TGLinearLayout: TGBaseLayout,TGLinearLayoutViewSizeClass { _ = sbvl.tg_sizeThatFits(sbvtgFrame.frame.size,inSizeClass:type) if sbvtgFrame.multiple { - sbvtgFrame.sizeClass = sbv.tgMatchBestSizeClass(type) //因为estimateLayoutRect执行后会还原,所以这里要重新设置 + sbvtgFrame.sizeClass = sbv.tgMatchBestSizeClass(type) //因为tg_sizeThatFits执行后会还原,所以这里要重新设置 } } } @@ -539,7 +539,7 @@ extension TGLinearLayout { } } - retWidth = maxSubviewWidth + lsc.tg_leadingPadding + lsc.tg_trailingPadding; + retWidth = maxSubviewWidth + lsc.tgLeadingPadding + lsc.tgTrailingPadding; } return retWidth @@ -643,7 +643,7 @@ extension TGLinearLayout { var fixedSizeHeight:CGFloat = 0 var fixedSpaceCount:Int = 0 var fixedSpaceHeight:CGFloat = 0 - var pos:CGFloat = lsc.tg_topPadding + var pos:CGFloat = lsc.tgTopPadding for sbv in sbs { let (sbvtgFrame, sbvsc) = self.tgGetSubviewFrameAndSizeClass(sbv) @@ -658,7 +658,7 @@ extension TGLinearLayout { rect.size.height = sbvsc.height.numberSize(rect.size.height) if (sbvsc.height.isRelaSizeEqualTo(lsc.height) && !lsc.height.isWrap) { - rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) } if sbvsc.height.isRelaSizeEqualTo(sbvsc.width) @@ -756,7 +756,7 @@ extension TGLinearLayout { //在包裹宽度且总体比重不为0时则,则需要还原最小的宽度,这样就不会使得宽度在横竖屏或者多次计算后越来越宽。 if lsc.height.isWrap && totalWeight != .zeroWeight { - var tempSelfHeight = lsc.tg_topPadding + lsc.tg_bottomPadding + var tempSelfHeight = lsc.tgTopPadding + lsc.tgBottomPadding if sbs.count > 1 { tempSelfHeight += CGFloat(sbs.count - 1) * lsc.tg_vspace @@ -770,7 +770,7 @@ extension TGLinearLayout { //剩余的可浮动的高度,那些weight不为0的从这个高度来进行分发 var isWeightShrinkSpace = false var weightShrinkSpaceTotalHeight:CGFloat = 0.0 - floatingHeight = selfSize.height - fixedHeight - lsc.tg_topPadding - lsc.tg_bottomPadding + floatingHeight = selfSize.height - fixedHeight - lsc.tgTopPadding - lsc.tgBottomPadding let sstMode:TGSubviewsShrinkType = TGSubviewsShrinkType(rawValue: lsc.tg_shrinkType.rawValue & 0x0F) //压缩策略 let sstContent:TGSubviewsShrinkType = TGSubviewsShrinkType(rawValue: lsc.tg_shrinkType.rawValue & 0xF0) //压缩内容 if _tgCGFloatLessOrEqual(floatingHeight, 0) @@ -830,7 +830,7 @@ extension TGLinearLayout { if totalWeight != .zeroWeight || (sstMode != .none && _tgCGFloatLessOrEqual(floatingHeight, 0)) { - pos = lsc.tg_topPadding + pos = lsc.tgTopPadding for sbv in sbs { let (sbvtgFrame, sbvsc) = self.tgGetSubviewFrameAndSizeClass(sbv) @@ -845,7 +845,9 @@ extension TGLinearLayout { //分别处理相对顶部边距和绝对顶部边距 if let t = sbvsc.top.weightVal { - topSpace = (t.rawValue / totalWeight.rawValue) * floatingHeight; + topSpace = _tgRoundNumber((t.rawValue / totalWeight.rawValue) * floatingHeight) + floatingHeight -= topSpace + totalWeight -= t if _tgCGFloatLessOrEqual(topSpace, 0) { topSpace = 0 @@ -872,7 +874,9 @@ extension TGLinearLayout { rect.origin.y = pos; if let t = sbvsc.height.weightVal { - var h:CGFloat = (t.rawValue / totalWeight.rawValue) * floatingHeight; + var h:CGFloat = _tgRoundNumber((t.rawValue / totalWeight.rawValue) * floatingHeight) + floatingHeight -= h + totalWeight -= t if _tgCGFloatLessOrEqual(h, 0) { h = 0; @@ -883,7 +887,9 @@ extension TGLinearLayout { } else if sbvsc.height.isFill { - var h:CGFloat = (100.0 / totalWeight.rawValue) * floatingHeight; + var h:CGFloat = _tgRoundNumber((100.0 / totalWeight.rawValue) * floatingHeight) + floatingHeight -= h + totalWeight -= TGWeight(100) if _tgCGFloatLessOrEqual(h, 0) { h = 0; @@ -898,7 +904,9 @@ extension TGLinearLayout { //分别处理相对底部边距和绝对底部边距 if let t = sbvsc.bottom.weightVal { - bottomSpace = (t.rawValue / totalWeight.rawValue) * floatingHeight; + bottomSpace = _tgRoundNumber((t.rawValue / totalWeight.rawValue) * floatingHeight) + floatingHeight -= bottomSpace + totalWeight -= t if _tgCGFloatLessOrEqual(bottomSpace, 0) { bottomSpace = 0; @@ -941,7 +949,7 @@ extension TGLinearLayout { } } - pos += lsc.tg_bottomPadding; + pos += lsc.tgBottomPadding; if lsc.height.isWrap @@ -1027,7 +1035,7 @@ extension TGLinearLayout { var vWidth = sbvsc.width.numberSize(sbvtgFrame.width) if (sbvsc.width.isRelaSizeEqualTo(lsc.width) && !lsc.width.isWrap) { - vWidth = sbvsc.width.measure(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + vWidth = sbvsc.width.measure(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) } vWidth = self.tgValidMeasure(sbvsc.width,sbv:sbv,calcSize:vWidth,sbvSize:sbvtgFrame.frame.size,selfLayoutSize:selfSize) @@ -1063,7 +1071,7 @@ extension TGLinearLayout { //在包裹宽度且总体比重不为0时则,则需要还原最小的宽度,这样就不会使得宽度在横竖屏或者多次计算后越来越宽。 if (lsc.width.isWrap && totalWeight != .zeroWeight) { - var tempSelfWidth = lsc.tg_leadingPadding + lsc.tg_trailingPadding + var tempSelfWidth = lsc.tgLeadingPadding + lsc.tgTrailingPadding if sbs.count > 1 { tempSelfWidth += CGFloat(sbs.count - 1) * lsc.tg_hspace @@ -1075,7 +1083,7 @@ extension TGLinearLayout { //剩余的可浮动的宽度,那些weight不为0的从这个高度来进行分发 var isWeightShrinkSpace = false //是否按比重缩小间距。。。 var weightShrinkSpaceTotalWidth:CGFloat = 0.0 - floatingWidth = selfSize.width - fixedWidth - lsc.tg_leadingPadding - lsc.tg_trailingPadding; + floatingWidth = selfSize.width - fixedWidth - lsc.tgLeadingPadding - lsc.tgTrailingPadding; if _tgCGFloatLessOrEqual(floatingWidth, 0) { var sstMode:TGSubviewsShrinkType = TGSubviewsShrinkType(rawValue: lsc.tg_shrinkType.rawValue & 0x0F) //压缩策略 @@ -1179,7 +1187,7 @@ extension TGLinearLayout { } //调整所有子视图的宽度 - var pos:CGFloat = lsc.tg_leadingPadding; + var pos:CGFloat = lsc.tgLeadingPadding; for sbv in sbs { let (sbvtgFrame, sbvsc) = self.tgGetSubviewFrameAndSizeClass(sbv) @@ -1198,7 +1206,7 @@ extension TGLinearLayout { if sbvsc.height.isRelaSizeEqualTo(lsc.height) { - rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) } @@ -1206,7 +1214,9 @@ extension TGLinearLayout { //计算出先对左边边距和绝对左边边距 if let t = sbvsc.leading.weightVal { - leadingSpace = (t.rawValue / totalWeight.rawValue) * floatingWidth; + leadingSpace = _tgRoundNumber((t.rawValue / totalWeight.rawValue) * floatingWidth) + floatingWidth -= leadingSpace + totalWeight -= t if _tgCGFloatLessOrEqual(leadingSpace, 0) { leadingSpace = 0 @@ -1234,7 +1244,9 @@ extension TGLinearLayout { rect.origin.x = pos; if let t = sbvsc.width.weightVal { - var w = (t.rawValue / totalWeight.rawValue) * floatingWidth; + var w = _tgRoundNumber((t.rawValue / totalWeight.rawValue) * floatingWidth) + floatingWidth -= w + totalWeight -= t if _tgCGFloatLessOrEqual(w,0) { w = 0 @@ -1244,7 +1256,9 @@ extension TGLinearLayout { } else if sbvsc.width.isFill { - var w = (100.0 / totalWeight.rawValue) * floatingWidth; + var w = _tgRoundNumber((100.0 / totalWeight.rawValue) * floatingWidth) + floatingWidth -= w + totalWeight -= TGWeight(100) if _tgCGFloatLessOrEqual(w,0) { w = 0 @@ -1260,7 +1274,9 @@ extension TGLinearLayout { //计算相对的右边边距和绝对的右边边距 if let t = sbvsc.trailing.weightVal { - trailingSpace = (t.rawValue / totalWeight.rawValue) * floatingWidth; + trailingSpace = _tgRoundNumber((t.rawValue / totalWeight.rawValue) * floatingWidth) + floatingWidth -= trailingSpace + totalWeight -= t if _tgCGFloatLessOrEqual(trailingSpace, 0) { trailingSpace = 0; @@ -1330,7 +1346,7 @@ extension TGLinearLayout { sbvtgFrame.frame = rect; } - pos += lsc.tg_trailingPadding; + pos += lsc.tgTrailingPadding; if lsc.width.isWrap { @@ -1339,7 +1355,7 @@ extension TGLinearLayout { if lsc.height.isWrap { - selfSize.height = maxSubviewHeight + lsc.tg_topPadding + lsc.tg_bottomPadding + selfSize.height = maxSubviewHeight + lsc.tgTopPadding + lsc.tgBottomPadding //调整所有子视图的高度 for sbv in sbs @@ -1374,7 +1390,7 @@ extension TGLinearLayout { var selfSize = selfSize selfSize.width = self.tgAdjustSelfWidth(sbs, selfSize:selfSize, lsc:lsc) - var floatingHeight:CGFloat = selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - totalHeight + var floatingHeight:CGFloat = selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - totalHeight if _tgCGFloatLessOrEqual(floatingHeight, 0) { floatingHeight = 0 @@ -1401,7 +1417,7 @@ extension TGLinearLayout { if (sbvsc.height.isRelaSizeEqualTo(lsc.height) && !lsc.height.isWrap) { - rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) canAddToNoWrapSbs = false } @@ -1452,12 +1468,12 @@ extension TGLinearLayout { if vertGravity == TGGravity.vert.top { - pos = lsc.tg_topPadding; + pos = lsc.tgTopPadding; } else if vertGravity == TGGravity.vert.center { - pos = (selfSize.height - totalHeight - lsc.tg_bottomPadding - lsc.tg_topPadding)/2.0; - pos += lsc.tg_topPadding; + pos = (selfSize.height - totalHeight - lsc.tgBottomPadding - lsc.tgTopPadding)/2.0; + pos += lsc.tgTopPadding; } else if vertGravity == TGGravity.vert.windowCenter { @@ -1473,28 +1489,28 @@ extension TGLinearLayout { } else if vertGravity == TGGravity.vert.bottom { - pos = selfSize.height - totalHeight - lsc.tg_bottomPadding + pos = selfSize.height - totalHeight - lsc.tgBottomPadding } else if vertGravity == TGGravity.vert.between { - pos = lsc.tg_topPadding; + pos = lsc.tgTopPadding; if sbs.count > 1 { - between = (selfSize.height - totalHeight - lsc.tg_topPadding - lsc.tg_bottomPadding) / CGFloat(sbs.count - 1) + between = (selfSize.height - totalHeight - lsc.tgTopPadding - lsc.tgBottomPadding) / CGFloat(sbs.count - 1) } } else if vertGravity == TGGravity.vert.fill { - pos = lsc.tg_topPadding + pos = lsc.tgTopPadding if noWrapsbsSet.count > 0 { - fill = (selfSize.height - totalHeight - lsc.tg_topPadding - lsc.tg_bottomPadding) / CGFloat(noWrapsbsSet.count) + fill = (selfSize.height - totalHeight - lsc.tgTopPadding - lsc.tgBottomPadding) / CGFloat(noWrapsbsSet.count) } } else { - pos = lsc.tg_topPadding + pos = lsc.tgTopPadding } @@ -1546,7 +1562,7 @@ extension TGLinearLayout { var maxSubviewHeight:CGFloat = 0; var selfSize = selfSize - floatingWidth = selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - totalWidth; + floatingWidth = selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - totalWidth; if _tgCGFloatLessOrEqual(floatingWidth, 0) { floatingWidth = 0 @@ -1574,13 +1590,13 @@ extension TGLinearLayout { if (sbvsc.width.isRelaSizeEqualTo(lsc.width) && !lsc.width.isWrap) { - rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) canAddToNoWrapSbs = false } if sbvsc.height.isRelaSizeEqualTo(lsc.height) { - rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) } if sbvsc.width.isRelaSizeEqualTo(sbvsc.height) @@ -1645,7 +1661,7 @@ extension TGLinearLayout { //调整自己的高度。 if lsc.height.isWrap { - selfSize.height = maxSubviewHeight + lsc.tg_topPadding + lsc.tg_bottomPadding; + selfSize.height = maxSubviewHeight + lsc.tgTopPadding + lsc.tgBottomPadding; } //根据对齐的方位来定位子视图的布局对齐 @@ -1655,12 +1671,12 @@ extension TGLinearLayout { if horzGravity == TGGravity.horz.leading { - pos = lsc.tg_leadingPadding + pos = lsc.tgLeadingPadding } else if horzGravity == TGGravity.horz.center { - pos = (selfSize.width - totalWidth - lsc.tg_leadingPadding - lsc.tg_trailingPadding)/2.0; - pos += lsc.tg_leadingPadding; + pos = (selfSize.width - totalWidth - lsc.tgLeadingPadding - lsc.tgTrailingPadding)/2.0; + pos += lsc.tgLeadingPadding; } else if horzGravity == TGGravity.horz.windowCenter { @@ -1679,29 +1695,29 @@ extension TGLinearLayout { } else if horzGravity == TGGravity.horz.trailing { - pos = selfSize.width - totalWidth - lsc.tg_trailingPadding; + pos = selfSize.width - totalWidth - lsc.tgTrailingPadding; } else if horzGravity == TGGravity.horz.between { - pos = lsc.tg_leadingPadding + pos = lsc.tgLeadingPadding if sbs.count > 1 { - between = (selfSize.width - totalWidth - lsc.tg_leadingPadding - lsc.tg_trailingPadding) / CGFloat(sbs.count - 1) + between = (selfSize.width - totalWidth - lsc.tgLeadingPadding - lsc.tgTrailingPadding) / CGFloat(sbs.count - 1) } } else if horzGravity == TGGravity.horz.fill { - pos = lsc.tg_leadingPadding + pos = lsc.tgLeadingPadding if noWrapsbsSet.count > 0 { - fill = (selfSize.width - totalWidth - lsc.tg_leadingPadding - lsc.tg_trailingPadding) / CGFloat(noWrapsbsSet.count) + fill = (selfSize.width - totalWidth - lsc.tgLeadingPadding - lsc.tgTrailingPadding) / CGFloat(noWrapsbsSet.count) } } else { - pos = lsc.tg_leadingPadding + pos = lsc.tgLeadingPadding } @@ -1769,7 +1785,7 @@ extension TGLinearLayout { fileprivate func tgCalcLeadingTrailingRect(horzGravity:TGGravity, selfSize:CGSize, sbv:UIView, sbvsc:TGViewSizeClassImpl, lsc:TGLinearLayoutViewSizeClassImpl, rect:inout CGRect) { - let floatingWidth = selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding + let floatingWidth = selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding let realLeadingMargin = sbvsc.leading.weightPosIn(floatingWidth) let realTrailingMargin = sbvsc.trailing.weightPosIn(floatingWidth) @@ -1798,7 +1814,7 @@ extension TGLinearLayout { fileprivate func tgCalcTopBottomRect(vertGravity:TGGravity, selfSize:CGSize, sbv:UIView, sbvsc:TGViewSizeClassImpl, lsc:TGLinearLayoutViewSizeClassImpl, rect:inout CGRect) { - let floatingHeight = selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding + let floatingHeight = selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding let realTopMargin = sbvsc.top.weightPosIn(floatingHeight) let realBottomMargin = sbvsc.bottom.weightPosIn(floatingHeight) diff --git a/TangramKit/TGPathLayout.swift b/TangramKit/TGPathLayout.swift index 653913f..5ca7c65 100644 --- a/TangramKit/TGPathLayout.swift +++ b/TangramKit/TGPathLayout.swift @@ -424,13 +424,13 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass { _ = sbvl.tg_sizeThatFits(sbvtgFrame.frame.size, inSizeClass: type) if sbvtgFrame.multiple { - sbvtgFrame.sizeClass = sbv.tgMatchBestSizeClass(type) //因为estimateLayoutRect执行后会还原,所以这里要重新设置 + sbvtgFrame.sizeClass = sbv.tgMatchBestSizeClass(type) //因为tg_sizeThatFits执行后会还原,所以这里要重新设置 } } } } - // var maxSize = CGSize(width: lsc.tg_leftPadding, height: lsc.tg_topPadding) + // var maxSize = CGSize(width: lsc.tgLeftPadding, height: lsc.tgTopPadding) //记录最小的y值和最大的y值 var minYPos = CGFloat.greatestFiniteMagnitude var maxYPos = -CGFloat.greatestFiniteMagnitude @@ -471,7 +471,7 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass { if let t = sbvsc.width.sizeVal { if t === lsc.width.realSize{ - rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tg_leftPadding - lsc.tg_rightPadding) + rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tgLeftPadding - lsc.tgRightPadding) }else{ rect.size.width = sbvsc.width.measure(t.view.tg_estimatedFrame.size.width) } @@ -484,7 +484,7 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass { if let t = sbvsc.height.sizeVal { if t === lsc.height.realSize{ - rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) }else{ rect.size.height = sbvsc.height.measure(t.view.tg_estimatedFrame.size.height) } @@ -540,7 +540,7 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass { if let t = sbvsc.width.sizeVal { if t === lsc.width.realSize { - rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tg_leftPadding - lsc.tg_rightPadding) + rect.size.width = sbvsc.width.measure(selfSize.width - lsc.tgLeftPadding - lsc.tgRightPadding) }else{ rect.size.width = sbvsc.width.measure(t.view.tg_estimatedFrame.size.width) } @@ -552,7 +552,7 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass { if let t = sbvsc.height.sizeVal { if (t === lsc.height.realSize){ - rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + rect.size.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) }else{ rect.size.height = sbvsc.height.measure(t.view.tg_estimatedFrame.size.height) } @@ -571,8 +571,8 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass { let rightMargin = sbvsc.right.absPos let bottomMargin = sbvsc.bottom.absPos - rect.origin.x = (selfSize.width - lsc.tg_leftPadding - lsc.tg_rightPadding)*tg_coordinateSetting.origin.x - rect.size.width * sbv.layer.anchorPoint.x + leftMargin - rightMargin + lsc.tg_leftPadding - rect.origin.y = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding)*tg_coordinateSetting.origin.y - rect.size.height * sbv.layer.anchorPoint.y + topMargin - bottomMargin + lsc.tg_topPadding + rect.origin.x = (selfSize.width - lsc.tgLeftPadding - lsc.tgRightPadding)*tg_coordinateSetting.origin.x - rect.size.width * sbv.layer.anchorPoint.x + leftMargin - rightMargin + lsc.tgLeftPadding + rect.origin.y = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding)*tg_coordinateSetting.origin.y - rect.size.height * sbv.layer.anchorPoint.y + topMargin - bottomMargin + lsc.tgTopPadding if _tgCGFloatLess(rect.minY , minYPos) { @@ -604,7 +604,7 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass { if maxYPos == -.greatestFiniteMagnitude { - maxYPos = lsc.tg_topPadding + lsc.tg_bottomPadding + maxYPos = lsc.tgTopPadding + lsc.tgBottomPadding } if minXPos == .greatestFiniteMagnitude @@ -614,7 +614,7 @@ open class TGPathLayout : TGBaseLayout,TGPathLayoutViewSizeClass { if maxXPos == -.greatestFiniteMagnitude { - maxXPos = lsc.tg_leftPadding + lsc.tg_rightPadding + maxXPos = lsc.tgLeftPadding + lsc.tgRightPadding } @@ -693,8 +693,9 @@ extension TGPathLayout{ ->[CGPoint] { var pathPointArray = [CGPoint]() - let selfWidth = bounds.width - self.tg_leftPadding - self.tg_rightPadding - let selfHeight = bounds.height - self.tg_topPadding - self.tg_bottomPadding + let lsc = self.tgCurrentSizeClass as! TGLayoutViewSizeClassImpl + let selfWidth = bounds.width - lsc.tgLeftPadding - lsc.tgRightPadding + let selfHeight = bounds.height - lsc.tgTopPadding - lsc.tgBottomPadding var startArg : CGFloat var endArg : CGFloat if let rectangularEquation = tg_rectangularEquation{ @@ -728,12 +729,12 @@ extension TGPathLayout{ arg in if let val = rectangularEquation(arg){ if tg_coordinateSetting.isReverse{ - let x = val + selfWidth * tg_coordinateSetting.origin.x + self.tg_leftPadding - let y = (tg_coordinateSetting.isMath ? -arg : arg) + selfHeight * tg_coordinateSetting.origin.y + self.tg_topPadding + let x = val + selfWidth * tg_coordinateSetting.origin.x + lsc.tgLeftPadding + let y = (tg_coordinateSetting.isMath ? -arg : arg) + selfHeight * tg_coordinateSetting.origin.y + lsc.tgTopPadding return CGPoint(x: x, y: y) }else{ - let x = arg + selfWidth * tg_coordinateSetting.origin.x + self.tg_leftPadding - let y = (tg_coordinateSetting.isMath ? -val : val) + selfHeight * tg_coordinateSetting.origin.y + self.tg_topPadding + let x = arg + selfWidth * tg_coordinateSetting.origin.x + lsc.tgLeftPadding + let y = (tg_coordinateSetting.isMath ? -val : val) + selfHeight * tg_coordinateSetting.origin.y + lsc.tgTopPadding return CGPoint(x: x, y: y) } @@ -772,13 +773,13 @@ extension TGPathLayout{ arg in if let val = parametricEquation(arg){ if tg_coordinateSetting.isReverse{ - let x = val.y + selfWidth * tg_coordinateSetting.origin.x + self.tg_leftPadding - let y = (tg_coordinateSetting.isMath ? -val.x : val.x) + selfHeight * tg_coordinateSetting.origin.y + self.tg_topPadding + let x = val.y + selfWidth * tg_coordinateSetting.origin.x + lsc.tgLeftPadding + let y = (tg_coordinateSetting.isMath ? -val.x : val.x) + selfHeight * tg_coordinateSetting.origin.y + lsc.tgTopPadding return CGPoint(x: x, y: y) }else{ - let x = val.x + selfWidth * tg_coordinateSetting.origin.x + self.tg_leftPadding - let y = (tg_coordinateSetting.isMath ? -val.y : val.y) + selfHeight * tg_coordinateSetting.origin.y + self.tg_topPadding + let x = val.x + selfWidth * tg_coordinateSetting.origin.x + lsc.tgLeftPadding + let y = (tg_coordinateSetting.isMath ? -val.y : val.y) + selfHeight * tg_coordinateSetting.origin.y + lsc.tgTopPadding return CGPoint(x: x, y: y) } @@ -805,13 +806,13 @@ extension TGPathLayout{ if let r = polarEquation(rad){ if tg_coordinateSetting.isReverse{ let y = r * cos(rad.value) - let x = r * sin(rad.value) + selfWidth * tg_coordinateSetting.origin.x + self.tg_leftPadding - let y1 = (tg_coordinateSetting.isMath ? -y : y) + selfHeight * tg_coordinateSetting.origin.y + self.tg_topPadding + let x = r * sin(rad.value) + selfWidth * tg_coordinateSetting.origin.x + lsc.tgLeftPadding + let y1 = (tg_coordinateSetting.isMath ? -y : y) + selfHeight * tg_coordinateSetting.origin.y + lsc.tgTopPadding return CGPoint(x: x, y: y1) }else{ let y = r * sin(rad.value) - let x = r * cos(rad.value) + selfWidth * tg_coordinateSetting.origin.x + self.tg_leftPadding - let y1 = (tg_coordinateSetting.isMath ? -y : y) + selfHeight * tg_coordinateSetting.origin.y + self.tg_topPadding + let x = r * cos(rad.value) + selfWidth * tg_coordinateSetting.origin.x + lsc.tgLeftPadding + let y1 = (tg_coordinateSetting.isMath ? -y : y) + selfHeight * tg_coordinateSetting.origin.y + lsc.tgTopPadding return CGPoint(x: x, y: y1) } }else{ diff --git a/TangramKit/TGRelativeLayout.swift b/TangramKit/TGRelativeLayout.swift index eeb2a20..13801ec 100644 --- a/TangramKit/TGRelativeLayout.swift +++ b/TangramKit/TGRelativeLayout.swift @@ -100,7 +100,7 @@ open class TGRelativeLayout: TGBaseLayout,TGRelativeLayoutViewSizeClass { if sbvtgFrame.multiple { - sbvtgFrame.sizeClass = sbv.tgMatchBestSizeClass(type) //因为estimateLayoutRect执行后会还原,所以这里要重新设置 + sbvtgFrame.sizeClass = sbv.tgMatchBestSizeClass(type) //因为tg_sizeThatFits执行后会还原,所以这里要重新设置 } } } @@ -187,7 +187,7 @@ extension TGRelativeLayout { if sbvsc.width.isFill && !self.tgIsNoLayoutSubview(sbv) { - sbvtgFrame.width = sbvsc.width.measure(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + sbvtgFrame.width = sbvsc.width.measure(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) } } @@ -212,7 +212,7 @@ extension TGRelativeLayout } else if sbvsc.centerX.numberVal != nil { - sbvtgFrame.leading = (selfSize.width - lsc.tg_trailingPadding - lsc.tg_leadingPadding - sbvtgFrame.width) / 2 + lsc.tg_leadingPadding + sbvCenterXMargin + sbvtgFrame.leading = (selfSize.width - lsc.tgTrailingPadding - lsc.tgLeadingPadding - sbvtgFrame.width) / 2 + lsc.tgLeadingPadding + sbvCenterXMargin if lsc.width.isWrap && sbvtgFrame.leading < 0 @@ -224,7 +224,7 @@ extension TGRelativeLayout } else if sbvsc.centerX.weightVal != nil { - sbvtgFrame.leading = (selfSize.width - lsc.tg_trailingPadding - lsc.tg_leadingPadding - sbvtgFrame.width) / 2 + lsc.tg_leadingPadding + sbvsc.centerX.weightPosIn(selfSize.width - lsc.tg_trailingPadding - lsc.tg_leadingPadding) + sbvtgFrame.leading = (selfSize.width - lsc.tgTrailingPadding - lsc.tgLeadingPadding - sbvtgFrame.width) / 2 + lsc.tgLeadingPadding + sbvsc.centerX.weightPosIn(selfSize.width - lsc.tgTrailingPadding - lsc.tgLeadingPadding) if lsc.width.isWrap && sbvtgFrame.leading < 0 @@ -250,17 +250,17 @@ extension TGRelativeLayout } else if sbvsc.leading.numberVal != nil { - sbvtgFrame.leading = sbvLeadingMargin + lsc.tg_leadingPadding + sbvtgFrame.leading = sbvLeadingMargin + lsc.tgLeadingPadding } else if sbvsc.leading.weightVal != nil { - sbvtgFrame.leading = sbvsc.leading.weightPosIn(selfSize.width - lsc.tg_trailingPadding - lsc.tg_leadingPadding) + lsc.tg_leadingPadding + sbvtgFrame.leading = sbvsc.leading.weightPosIn(selfSize.width - lsc.tgTrailingPadding - lsc.tgLeadingPadding) + lsc.tgLeadingPadding } if sbvsc.width.isFill && !self.tgIsNoLayoutSubview(sbv) { - //lsc.tg_leadingPadding 这里因为sbvtgFrame.leading已经包含了leftPadding所以这里不需要再减 - sbvtgFrame.width = sbvsc.width.measure(selfSize.width - lsc.tg_trailingPadding - sbvtgFrame.leading) + //lsc.tgLeadingPadding 这里因为sbvtgFrame.leading已经包含了leftPadding所以这里不需要再减 + sbvtgFrame.width = sbvsc.width.measure(selfSize.width - lsc.tgTrailingPadding - sbvtgFrame.leading) } sbvtgFrame.trailing = sbvtgFrame.leading + sbvtgFrame.width @@ -283,16 +283,16 @@ extension TGRelativeLayout } else if sbvsc.trailing.numberVal != nil { - sbvtgFrame.trailing = selfSize.width - lsc.tg_trailingPadding - sbvTrailingMargin + sbvLeadingMargin + sbvtgFrame.trailing = selfSize.width - lsc.tgTrailingPadding - sbvTrailingMargin + sbvLeadingMargin } else if sbvsc.trailing.weightVal != nil { - sbvtgFrame.trailing = selfSize.width - lsc.tg_trailingPadding - sbvsc.trailing.weightPosIn(selfSize.width - lsc.tg_trailingPadding - lsc.tg_leadingPadding) + sbvLeadingMargin + sbvtgFrame.trailing = selfSize.width - lsc.tgTrailingPadding - sbvsc.trailing.weightPosIn(selfSize.width - lsc.tgTrailingPadding - lsc.tgLeadingPadding) + sbvLeadingMargin } if sbvsc.width.isFill && !self.tgIsNoLayoutSubview(sbv) { - sbvtgFrame.width = sbvsc.width.measure(sbvtgFrame.trailing - sbvLeadingMargin - lsc.tg_leadingPadding) + sbvtgFrame.width = sbvsc.width.measure(sbvtgFrame.trailing - sbvLeadingMargin - lsc.tgLeadingPadding) } sbvtgFrame.leading = sbvtgFrame.trailing - sbvtgFrame.width @@ -303,10 +303,10 @@ extension TGRelativeLayout { if sbvsc.width.isFill && !self.tgIsNoLayoutSubview(sbv) { - sbvtgFrame.width = sbvsc.width.measure(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + sbvtgFrame.width = sbvsc.width.measure(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) } - sbvtgFrame.leading = sbvLeadingMargin + lsc.tg_leadingPadding + sbvtgFrame.leading = sbvLeadingMargin + lsc.tgLeadingPadding sbvtgFrame.trailing = sbvtgFrame.leading + sbvtgFrame.width } } @@ -389,7 +389,7 @@ extension TGRelativeLayout { if sbvsc.height.isFill && !self.tgIsNoLayoutSubview(sbv) { - sbvtgFrame.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + sbvtgFrame.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) } } if let t = sbvsc.centerY.posVal @@ -413,7 +413,7 @@ extension TGRelativeLayout } else if sbvsc.centerY.numberVal != nil { - sbvtgFrame.top = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - sbvtgFrame.height) / 2 + lsc.tg_topPadding + sbvCenterYMargin + sbvtgFrame.top = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - sbvtgFrame.height) / 2 + lsc.tgTopPadding + sbvCenterYMargin if lsc.height.isWrap && sbvtgFrame.top < 0 { @@ -424,7 +424,7 @@ extension TGRelativeLayout } else if sbvsc.centerY.weightVal != nil { - sbvtgFrame.top = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - sbvtgFrame.height) / 2 + lsc.tg_topPadding + sbvsc.centerY.weightPosIn(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + sbvtgFrame.top = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - sbvtgFrame.height) / 2 + lsc.tgTopPadding + sbvsc.centerY.weightPosIn(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) if lsc.height.isWrap && sbvtgFrame.top < 0 { @@ -452,17 +452,17 @@ extension TGRelativeLayout } else if sbvsc.top.numberVal != nil { - sbvtgFrame.top = sbvTopMargin + lsc.tg_topPadding + sbvtgFrame.top = sbvTopMargin + lsc.tgTopPadding } else if sbvsc.top.weightVal != nil { - sbvtgFrame.top = sbvsc.top.weightPosIn(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + lsc.tg_topPadding + sbvtgFrame.top = sbvsc.top.weightPosIn(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) + lsc.tgTopPadding } if sbvsc.height.isFill && !self.tgIsNoLayoutSubview(sbv) { - //lsc.tg_topPadding 这里因为sbvtgFrame.top已经包含了topPadding所以这里不需要再减 - sbvtgFrame.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - sbvtgFrame.top) + //lsc.tgTopPadding 这里因为sbvtgFrame.top已经包含了topPadding所以这里不需要再减 + sbvtgFrame.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - sbvtgFrame.top) } sbvtgFrame.bottom = sbvtgFrame.top + sbvtgFrame.height @@ -485,16 +485,16 @@ extension TGRelativeLayout } else if sbvsc.bottom.numberVal != nil { - sbvtgFrame.bottom = selfSize.height - sbvBottomMargin - lsc.tg_bottomPadding + sbvTopMargin + sbvtgFrame.bottom = selfSize.height - sbvBottomMargin - lsc.tgBottomPadding + sbvTopMargin } else if sbvsc.bottom.weightVal != nil { - sbvtgFrame.bottom = selfSize.height - sbvsc.bottom.weightPosIn(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) - lsc.tg_bottomPadding + sbvTopMargin + sbvtgFrame.bottom = selfSize.height - sbvsc.bottom.weightPosIn(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) - lsc.tgBottomPadding + sbvTopMargin } if sbvsc.height.isFill && !self.tgIsNoLayoutSubview(sbv) { - sbvtgFrame.height = sbvsc.height.measure(sbvtgFrame.bottom - sbvTopMargin - lsc.tg_topPadding) + sbvtgFrame.height = sbvsc.height.measure(sbvtgFrame.bottom - sbvTopMargin - lsc.tgTopPadding) } sbvtgFrame.top = sbvtgFrame.bottom - sbvtgFrame.height @@ -505,10 +505,10 @@ extension TGRelativeLayout { if sbvsc.height.isFill && !self.tgIsNoLayoutSubview(sbv) { - sbvtgFrame.height = sbvsc.height.measure(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + sbvtgFrame.height = sbvsc.height.measure(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) } - sbvtgFrame.top = sbvTopMargin + lsc.tg_topPadding + sbvtgFrame.top = sbvTopMargin + lsc.tgTopPadding sbvtgFrame.bottom = sbvtgFrame.top + sbvtgFrame.height } } @@ -579,7 +579,7 @@ extension TGRelativeLayout } else if let t = sbvsc.width.weightVal { - sbvtgFrame.width = self.tgValidMeasure(sbvsc.width, sbv: sbv, calcSize: sbvsc.width.measure((selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) * t.rawValue/100), sbvSize: sbvtgFrame.frame.size, selfLayoutSize: selfSize) + sbvtgFrame.width = self.tgValidMeasure(sbvsc.width, sbv: sbv, calcSize: sbvsc.width.measure((selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) * t.rawValue/100), sbvSize: sbvtgFrame.frame.size, selfLayoutSize: selfSize) } if self.tgIsNoLayoutSubview(sbv) @@ -594,14 +594,14 @@ extension TGRelativeLayout sbvtgFrame.leading = tgCalcRelationalSubview(t.view, lsc:lsc, gravity:t.type, selfSize: selfSize) + sbvsc.leading.absPos } else { - sbvtgFrame.leading = sbvsc.leading.weightPosIn(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) + lsc.tg_leadingPadding + sbvtgFrame.leading = sbvsc.leading.weightPosIn(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) + lsc.tgLeadingPadding } if let t = sbvsc.trailing.posVal { sbvtgFrame.trailing = tgCalcRelationalSubview(t.view, lsc:lsc, gravity:t.type, selfSize: selfSize) - sbvsc.trailing.absPos } else { - sbvtgFrame.trailing = selfSize.width - sbvsc.trailing.weightPosIn(selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) - lsc.tg_trailingPadding + sbvtgFrame.trailing = selfSize.width - sbvsc.trailing.weightPosIn(selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) - lsc.tgTrailingPadding } sbvtgFrame.width = sbvtgFrame.trailing - sbvtgFrame.leading @@ -643,7 +643,7 @@ extension TGRelativeLayout } else if let t = sbvsc.height.weightVal { - sbvtgFrame.height = self.tgValidMeasure(sbvsc.height, sbv: sbv, calcSize: sbvsc.height.measure((selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) * t.rawValue/100), sbvSize: sbvtgFrame.frame.size, selfLayoutSize: selfSize) + sbvtgFrame.height = self.tgValidMeasure(sbvsc.height, sbv: sbv, calcSize: sbvsc.height.measure((selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) * t.rawValue/100), sbvSize: sbvtgFrame.frame.size, selfLayoutSize: selfSize) } if self.tgIsNoLayoutSubview(sbv) @@ -657,14 +657,14 @@ extension TGRelativeLayout sbvtgFrame.top = self.tgCalcRelationalSubview(t.view,lsc:lsc, gravity:t.type, selfSize: selfSize) + sbvsc.top.absPos } else { - sbvtgFrame.top = sbvsc.top.weightPosIn(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) + lsc.tg_topPadding + sbvtgFrame.top = sbvsc.top.weightPosIn(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) + lsc.tgTopPadding } if let t = sbvsc.bottom.posVal { sbvtgFrame.bottom = self.tgCalcRelationalSubview(t.view,lsc:lsc, gravity:t.type, selfSize: selfSize) - sbvsc.bottom.absPos } else { - sbvtgFrame.bottom = selfSize.height - sbvsc.bottom.weightPosIn(selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) - lsc.tg_bottomPadding + sbvtgFrame.bottom = selfSize.height - sbvsc.bottom.weightPosIn(selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) - lsc.tgBottomPadding } sbvtgFrame.height = sbvtgFrame.bottom - sbvtgFrame.top @@ -787,7 +787,7 @@ extension TGRelativeLayout } } - var floatWidth: CGFloat = selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding + totalAdd + var floatWidth: CGFloat = selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding + totalAdd if _tgCGFloatLessOrEqual(floatWidth, 0) { floatWidth = 0 @@ -856,7 +856,7 @@ extension TGRelativeLayout } } - var floatHeight = selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding + totalAdd + var floatHeight = selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding + totalAdd if _tgCGFloatLessOrEqual(floatHeight, 0) { floatHeight = 0 @@ -939,8 +939,8 @@ extension TGRelativeLayout } - var leadingOffset: CGFloat = (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding - totalWidth - totalOffset) / 2.0 - leadingOffset += lsc.tg_leadingPadding + var leadingOffset: CGFloat = (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding - totalWidth - totalOffset) / 2.0 + leadingOffset += lsc.tgLeadingPadding var prev:AnyObject! = leadingOffset as AnyObject! sbv.tg_leading.equal(leadingOffset) @@ -1007,8 +1007,8 @@ extension TGRelativeLayout } - var topOffset: CGFloat = (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding - totalHeight - totalOffset) / 2.0 - topOffset += lsc.tg_topPadding + var topOffset: CGFloat = (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding - totalHeight - totalOffset) / 2.0 + topOffset += lsc.tgTopPadding var prev:AnyObject! = topOffset as AnyObject! sbv.tg_top.equal(topOffset) @@ -1035,8 +1035,8 @@ extension TGRelativeLayout } - var maxWidth = lsc.tg_leadingPadding + lsc.tg_trailingPadding - var maxHeight = lsc.tg_topPadding + lsc.tg_bottomPadding + var maxWidth = lsc.tgLeadingPadding + lsc.tgTrailingPadding + var maxHeight = lsc.tgTopPadding + lsc.tgBottomPadding for sbv: UIView in self.subviews { @@ -1061,9 +1061,9 @@ extension TGRelativeLayout if isWrap { - maxWidth = self.tgCalcMaxWrapSize(sbvHead: sbvsc.leading, sbvCenter: sbvsc.centerX, sbvTail: sbvsc.trailing, sbvSize: sbvsc.width, sbvMeasure: sbvtgFrame.width, sbvMinPos: sbvtgFrame.leading, sbvMaxPos: sbvtgFrame.trailing, headPadding: lsc.tg_leadingPadding, tailPadding: lsc.tg_trailingPadding, lscSize: lsc.width, maxSize: maxWidth, recalc: &recalc) + maxWidth = self.tgCalcMaxWrapSize(sbvHead: sbvsc.leading, sbvCenter: sbvsc.centerX, sbvTail: sbvsc.trailing, sbvSize: sbvsc.width, sbvMeasure: sbvtgFrame.width, sbvMinPos: sbvtgFrame.leading, sbvMaxPos: sbvtgFrame.trailing, headPadding: lsc.tgLeadingPadding, tailPadding: lsc.tgTrailingPadding, lscSize: lsc.width, maxSize: maxWidth, recalc: &recalc) - maxHeight = self.tgCalcMaxWrapSize(sbvHead: sbvsc.top, sbvCenter: sbvsc.centerY, sbvTail: sbvsc.bottom, sbvSize: sbvsc.height, sbvMeasure: sbvtgFrame.height, sbvMinPos: sbvtgFrame.top, sbvMaxPos: sbvtgFrame.bottom, headPadding: lsc.tg_topPadding, tailPadding: lsc.tg_bottomPadding, lscSize: lsc.height, maxSize: maxHeight, recalc: &recalc) + maxHeight = self.tgCalcMaxWrapSize(sbvHead: sbvsc.top, sbvCenter: sbvsc.centerY, sbvTail: sbvsc.bottom, sbvSize: sbvsc.height, sbvMeasure: sbvtgFrame.height, sbvMinPos: sbvtgFrame.top, sbvMaxPos: sbvtgFrame.bottom, headPadding: lsc.tgTopPadding, tailPadding: lsc.tgBottomPadding, lscSize: lsc.height, maxSize: maxHeight, recalc: &recalc) } } @@ -1167,7 +1167,7 @@ extension TGRelativeLayout switch gravity { case TGGravity.horz.leading: if sbv == self || sbv == nil { - return lsc.tg_leadingPadding + return lsc.tgLeadingPadding } if sbvtgFrame.leading != CGFloat.greatestFiniteMagnitude { @@ -1182,7 +1182,7 @@ extension TGRelativeLayout case TGGravity.horz.trailing: if sbv == self || sbv == nil { - return selfSize.width - lsc.tg_trailingPadding + return selfSize.width - lsc.tgTrailingPadding } @@ -1196,7 +1196,7 @@ extension TGRelativeLayout case TGGravity.vert.top: if sbv == self || sbv == nil { - return lsc.tg_topPadding + return lsc.tgTopPadding } if sbvtgFrame.top != CGFloat.greatestFiniteMagnitude { @@ -1209,7 +1209,7 @@ extension TGRelativeLayout case TGGravity.vert.bottom: if sbv == self || sbv == nil { - return selfSize.height - lsc.tg_bottomPadding + return selfSize.height - lsc.tgBottomPadding } if sbvtgFrame.bottom != CGFloat.greatestFiniteMagnitude { @@ -1222,7 +1222,7 @@ extension TGRelativeLayout case TGGravity.horz.fill: if sbv == self || sbv == nil { - return selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding + return selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding } if sbvtgFrame.width != CGFloat.greatestFiniteMagnitude { @@ -1234,7 +1234,7 @@ extension TGRelativeLayout case TGGravity.vert.fill: if sbv == self || sbv == nil { - return selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding + return selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding } if sbvtgFrame.height != CGFloat.greatestFiniteMagnitude { @@ -1246,7 +1246,7 @@ extension TGRelativeLayout case TGGravity.horz.center: if sbv == self || sbv == nil { - return (selfSize.width - lsc.tg_leadingPadding - lsc.tg_trailingPadding) / 2 + lsc.tg_leadingPadding + return (selfSize.width - lsc.tgLeadingPadding - lsc.tgTrailingPadding) / 2 + lsc.tgLeadingPadding } @@ -1260,7 +1260,7 @@ extension TGRelativeLayout case TGGravity.vert.center: if sbv == self || sbv == nil { - return (selfSize.height - lsc.tg_topPadding - lsc.tg_bottomPadding) / 2 + lsc.tg_topPadding + return (selfSize.height - lsc.tgTopPadding - lsc.tgBottomPadding) / 2 + lsc.tgTopPadding } diff --git a/TangramKit/TGTableLayout.swift b/TangramKit/TGTableLayout.swift index f7e4129..cff5a8e 100644 --- a/TangramKit/TGTableLayout.swift +++ b/TangramKit/TGTableLayout.swift @@ -50,6 +50,11 @@ 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 + { + return tg_insertRow(size: rowSize, colSize:TGTableLayout._stgColCountTag - CGFloat(colCount), rowIndex: self.tg_rowCount) + } + /** * 在指定的位置插入一个新行 */ @@ -83,6 +88,13 @@ open class TGTableLayout: TGLinearLayout { } + public func tg_insertRow(size rowSize: TGTableRowColSizeType, colCount : UInt, rowIndex : Int) ->TGLinearLayout + { + //这里特殊处理用-100000 - colCount 来表示一个特殊的列尺寸。其实是数量。 + return tg_insertRow(size: rowSize, colSize: TGTableLayout._stgColCountTag - CGFloat(colCount), rowIndex: rowIndex) + } + + /** * 删除一行 */ @@ -151,13 +163,31 @@ open class TGTableLayout: TGLinearLayout { } else { - if (rowsc.tg_orientation == .horz) - { - colsc.tg_width.equalHelper(val:rowView.colSize) - } - else + if let v = rowView.colSize as? CGFloat { - colsc.tg_height.equalHelper(val:rowView.colSize) + if v < TGTableLayout._stgColCountTag + { + let colCount = TGTableLayout._stgColCountTag - v + if rowsc.tg_orientation == .horz + { + colsc.tg_width.equalHelper(val:rowView.tg_width, increment:-1 * rowView.tg_hspace * (colCount - 1.0) / colCount, multiple:1.0 / colCount) + } + else + { + colsc.tg_height.equalHelper(val:rowView.tg_height,increment:-1 * rowView.tg_vspace * (colCount - 1.0) / colCount, multiple:1.0 / colCount) + } + } + else + { + if (rowsc.tg_orientation == .horz) + { + colsc.tg_width.equalHelper(val:rowView.colSize) + } + else + { + colsc.tg_height.equalHelper(val:rowView.colSize) + } + } } } @@ -319,6 +349,7 @@ open class TGTableLayout: TGLinearLayout { return TGTableLayoutViewSizeClassImpl(view:self) } + static fileprivate let _stgColCountTag:CGFloat = -100000 } /** @@ -343,9 +374,14 @@ extension IndexPath { } } + + private class TGTableRowLayout: TGLinearLayout,TGTableLayoutViewSizeClass { + + + var rowSize: TGTableRowColSizeType - var colSize: TGTableRowColSizeType + var colSize:TGTableRowColSizeType init(orientation:TGOrientation,rowSize:TGTableRowColSizeType, colSize:TGTableRowColSizeType) { @@ -386,7 +422,19 @@ private class TGTableRowLayout: TGLinearLayout,TGTableLayoutViewSizeClass { } } + + var isNoWrap = false if let v = colSize as? TGLayoutSize, v === TGLayoutSize.average || v === TGLayoutSize.fill + { + isNoWrap = true + } + + if let v = colSize as? CGFloat, v < TGTableLayout._stgColCountTag + { + isNoWrap = true + } + + if isNoWrap { if (orientation == .horz) { diff --git a/TangramKit/TangramKit.swift b/TangramKit/TangramKit.swift index 79546d2..dd7d975 100644 --- a/TangramKit/TangramKit.swift +++ b/TangramKit/TangramKit.swift @@ -53,7 +53,7 @@ */ -//Current version is 1.1.1, please open: https://github.com/youngsoft/TangramKit/blob/master/CHANGELOG.md to show the changes. +//Current version is 1.1.2, please open: https://github.com/youngsoft/TangramKit/blob/master/CHANGELOG.md to show the changes. @@ -285,6 +285,11 @@ public func +=( lhs:inout TGWeight, rhs:TGWeight) lhs.rawValue += rhs.rawValue } +public func -=( lhs:inout TGWeight, rhs:TGWeight) +{ + lhs.rawValue -= rhs.rawValue +} + public func +(lhs:TGWeight, rhs:TGWeight) ->TGWeight { return TGWeight(lhs.rawValue + rhs.rawValue) diff --git a/TangramKitDemo/AppDelegate.swift b/TangramKitDemo/AppDelegate.swift index 719922c..eae95ea 100644 --- a/TangramKitDemo/AppDelegate.swift +++ b/TangramKitDemo/AppDelegate.swift @@ -18,6 +18,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { + + + // TGBaseLayout.appearance().TG TGDimeAdapter.template(CGSize(width: 375, height: 667)) self.window = UIWindow(frame: UIScreen.main.bounds) diff --git a/TangramKitDemo/FloatLayoutDemo/FOLTest1ViewController.swift b/TangramKitDemo/FloatLayoutDemo/FOLTest1ViewController.swift index 36b80e3..8100964 100644 --- a/TangramKitDemo/FloatLayoutDemo/FOLTest1ViewController.swift +++ b/TangramKitDemo/FloatLayoutDemo/FOLTest1ViewController.swift @@ -210,7 +210,7 @@ class FOLTest1ViewController: UIViewController { self.floatLayout.tg_layoutAnimationWithDuration(0.3) } - func handleAddSubview(_ sender: AnyObject) { + @objc func handleAddSubview(_ sender: AnyObject) { if (self.whTextField.text!.isEmpty) { @@ -223,7 +223,7 @@ class FOLTest1ViewController: UIViewController { } - func handleChangeOrientation(_ sender: AnyObject) { + @objc func handleChangeOrientation(_ sender: AnyObject) { //调整布局方向 if (self.floatLayout.tg_orientation == .vert) @@ -239,7 +239,7 @@ class FOLTest1ViewController: UIViewController { } - func handleWeightStepper(_ sender: UIStepper) { + @objc func handleWeightStepper(_ sender: UIStepper) { if sender == self.widthWeightStepper { @@ -256,7 +256,7 @@ class FOLTest1ViewController: UIViewController { } - func handleDelTag(_ sender:UIButton) + @objc func handleDelTag(_ sender:UIButton) { sender.removeFromSuperview() diff --git a/TangramKitDemo/FloatLayoutDemo/FOLTest2ViewController.swift b/TangramKitDemo/FloatLayoutDemo/FOLTest2ViewController.swift index 73bd0d8..50f7c54 100644 --- a/TangramKitDemo/FloatLayoutDemo/FOLTest2ViewController.swift +++ b/TangramKitDemo/FloatLayoutDemo/FOLTest2ViewController.swift @@ -56,62 +56,62 @@ class FOLTest2ViewController: UIViewController { [ "selector":#selector(createItemLayout1_1), "width":CGFloat(0.5), - "height":CGFloat(sItemLayoutHeight*2) + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight*2) ], [ "selector":#selector(createItemLayout1_2), "width":CGFloat(0.5), - "height":CGFloat(sItemLayoutHeight), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight), ], [ "selector":#selector(createItemLayout1_3), "width":CGFloat(0.5), - "height":CGFloat(sItemLayoutHeight), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight), ], [ "selector":#selector(createItemLayout2_1), "width":CGFloat(0.5), - "height":CGFloat(sItemLayoutHeight * 2), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight * 2), ], [ "selector":#selector(createItemLayout2_1), "width":CGFloat(0.25), - "height":CGFloat(sItemLayoutHeight * 2), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight * 2), ], [ "selector":#selector(createItemLayout2_1), "width":CGFloat(1.0), - "height":CGFloat(sItemLayoutHeight), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight), ], [ "selector":#selector(createItemLayout3_1), "width":CGFloat(0.4), - "height":CGFloat(sItemLayoutHeight * 2), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight * 2), ], [ "selector":#selector(createItemLayout3_2), "width":CGFloat(0.6), - "height":CGFloat(sItemLayoutHeight), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight), ], [ "selector":#selector(createItemLayout3_2), "width":CGFloat(0.4), - "height":CGFloat(sItemLayoutHeight), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight), ], [ "selector":#selector(createItemLayout4_1), "width":CGFloat(0.5), - "height":CGFloat(sItemLayoutHeight), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight), ], [ "selector":#selector(createItemLayout4_2), "width":CGFloat(0.25), - "height":CGFloat(sItemLayoutHeight + 20), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight + 20), ], [ "selector":#selector(createItemLayout5_1), "width":CGFloat(0.25), - "height":CGFloat(sItemLayoutHeight + 20), + "height":CGFloat(FOLTest2ViewController.sItemLayoutHeight + 20), ] ] @@ -288,7 +288,7 @@ extension FOLTest2ViewController //品牌特卖主条目布局,这是一个从上到下的布局,因此可以用上下浮动来实现。 - func createItemLayout1_1(_ dataModel:FOLTest2DataModel) ->TGFloatLayout + @objc func createItemLayout1_1(_ dataModel:FOLTest2DataModel) ->TGFloatLayout { /* 这个例子是为了重点演示浮动布局,所以里面的所有条目布局都用了浮动布局。您也可以使用其他布局来建立您的条目布局。 @@ -325,7 +325,7 @@ extension FOLTest2ViewController } //天猫超时条目布局,这是一个整体左右结构,因此用左右浮动布局来实现。 - func createItemLayout1_2(_ dataModel:FOLTest2DataModel) ->TGFloatLayout + @objc func createItemLayout1_2(_ dataModel:FOLTest2DataModel) ->TGFloatLayout { //建立左右浮动布局 let itemLayout = TGFloatLayout(.vert) @@ -362,7 +362,7 @@ extension FOLTest2ViewController } //建立品牌特卖的其他条目布局,这种布局整体是左右结构,因此建立左右浮动布局。 - func createItemLayout1_3(_ dataModel:FOLTest2DataModel) ->TGFloatLayout + @objc func createItemLayout1_3(_ dataModel:FOLTest2DataModel) ->TGFloatLayout { let itemLayout = TGFloatLayout(.vert) @@ -409,7 +409,7 @@ extension FOLTest2ViewController } //建立超级品牌日布局,这里因为就只有一张图,所以设置布局的背景图片即可。 - func createItemLayout2_1(_ dataModel:FOLTest2DataModel) ->TGFloatLayout + @objc func createItemLayout2_1(_ dataModel:FOLTest2DataModel) ->TGFloatLayout { let itemLayout = TGFloatLayout(.vert) //直接设置背景图片。 @@ -420,7 +420,7 @@ extension FOLTest2ViewController //精选市场主条目布局,这个布局整体从上到下因此用上下浮动布局建立。 - func createItemLayout3_1(_ dataModel:FOLTest2DataModel) ->TGFloatLayout + @objc func createItemLayout3_1(_ dataModel:FOLTest2DataModel) ->TGFloatLayout { let itemLayout = TGFloatLayout(.horz) @@ -473,7 +473,7 @@ extension FOLTest2ViewController } //建立精选市场其他条目布局,这个布局整体还是从上到下,因此用上下浮动布局 - func createItemLayout3_2(_ dataModel:FOLTest2DataModel) ->TGFloatLayout + @objc func createItemLayout3_2(_ dataModel:FOLTest2DataModel) ->TGFloatLayout { let itemLayout = TGFloatLayout(.horz) @@ -483,7 +483,7 @@ extension FOLTest2ViewController titleLabel.font = UIFont.boldSystemFont(ofSize: 15) titleLabel.tg_leading.equal(5) titleLabel.tg_top.equal(5) - titleLabel.tg_width.equal(itemLayout.tg_width,multiple:0.5) + titleLabel.tg_width.equal(itemLayout.tg_width,increment:-2.5, multiple:0.5) titleLabel.sizeToFit() itemLayout.addSubview(titleLabel) @@ -493,7 +493,7 @@ extension FOLTest2ViewController subTitleLabel.font = UIFont.systemFont(ofSize: 11) subTitleLabel.tg_leading.equal(5) subTitleLabel.tg_top.equal(5) - subTitleLabel.tg_width.equal(itemLayout.tg_width,multiple:0.5) + subTitleLabel.tg_width.equal(itemLayout.tg_width,increment:-2.5,multiple:0.5) subTitleLabel.sizeToFit() itemLayout.addSubview(subTitleLabel) @@ -505,7 +505,7 @@ extension FOLTest2ViewController priceLabel.tg_leading.equal(5) priceLabel.tg_bottom.equal(5) priceLabel.tg_reverseFloat = true - priceLabel.tg_width.equal(itemLayout.tg_width,multiple:0.5) + priceLabel.tg_width.equal(itemLayout.tg_width,increment:-2.5,multiple:0.5) priceLabel.sizeToFit() itemLayout.addSubview(priceLabel) @@ -516,13 +516,13 @@ extension FOLTest2ViewController descLabel.textColor = UIColor.lightGray descLabel.tg_leading.equal(5) descLabel.tg_reverseFloat = true - descLabel.tg_width.equal(itemLayout.tg_width,multiple:0.5) + descLabel.tg_width.equal(itemLayout.tg_width,increment:-2.5,multiple:0.5) descLabel.sizeToFit() itemLayout.addSubview(descLabel) //向上浮动,因为宽度无法再容纳,所以这里会换列继续向上浮动。 let imageView = UIImageView(image:UIImage(named:dataModel.image)) - imageView.tg_width.equal(itemLayout.tg_width,multiple:0.5) + imageView.tg_width.equal(itemLayout.tg_width,increment:-2.5,multiple:0.5) imageView.tg_height.equal(itemLayout.tg_height); itemLayout.addSubview(imageView) @@ -532,7 +532,7 @@ extension FOLTest2ViewController } //热门市场主条目布局,这个结构可以用上下浮动布局也可以用左右浮动布局。 - func createItemLayout4_1(_ dataModel:FOLTest2DataModel) ->TGFloatLayout + @objc func createItemLayout4_1(_ dataModel:FOLTest2DataModel) ->TGFloatLayout { let itemLayout = TGFloatLayout(.horz) @@ -541,7 +541,7 @@ extension FOLTest2ViewController titleLabel.font = UIFont.boldSystemFont(ofSize: 15) titleLabel.tg_leading.equal(5) titleLabel.tg_top.equal(5) - titleLabel.tg_width.equal(itemLayout.tg_width,multiple:0.5) + titleLabel.tg_width.equal(itemLayout.tg_width,increment:-2.5,multiple:0.5) titleLabel.sizeToFit() itemLayout.addSubview(titleLabel) @@ -551,13 +551,13 @@ extension FOLTest2ViewController subTitleLabel.font = UIFont.systemFont(ofSize: 11) subTitleLabel.tg_leading.equal(5) subTitleLabel.tg_top.equal(5) - subTitleLabel.tg_width.equal(itemLayout.tg_width,multiple:0.5) + subTitleLabel.tg_width.equal(itemLayout.tg_width,increment:-2.5,multiple:0.5) subTitleLabel.sizeToFit() itemLayout.addSubview(subTitleLabel) //继续向上浮动,这里因为高度和父布局高度一致,因此会换列浮动。 let imageView = UIImageView(image:UIImage(named:dataModel.image)) - imageView.tg_width.equal(itemLayout.tg_width,multiple:0.5) + imageView.tg_width.equal(itemLayout.tg_width,increment:-2.5,multiple:0.5) imageView.tg_height.equal(itemLayout.tg_height); itemLayout.addSubview(imageView) @@ -565,7 +565,7 @@ extension FOLTest2ViewController } //热门市场其他条目布局,这个整体是上下布局,因此用上下浮动布局。 - func createItemLayout4_2(_ dataModel:FOLTest2DataModel) ->TGFloatLayout + @objc func createItemLayout4_2(_ dataModel:FOLTest2DataModel) ->TGFloatLayout { let itemLayout = TGFloatLayout(.horz) @@ -597,7 +597,7 @@ extension FOLTest2ViewController //主题市场条目布局,这个整体就是上下浮动布局 - func createItemLayout5_1(_ dataModel:FOLTest2DataModel) ->TGFloatLayout + @objc func createItemLayout5_1(_ dataModel:FOLTest2DataModel) ->TGFloatLayout { let itemLayout = TGFloatLayout(.horz) @@ -634,7 +634,7 @@ extension FOLTest2ViewController extension FOLTest2ViewController { - func handleItemLayoutTap(sender:UIView!) + @objc func handleItemLayoutTap(sender:UIView!) { let sectionIndex = sender.tag / FOLTest2ViewController.sBaseTag; let itemIndex = sender.tag % FOLTest2ViewController.sBaseTag; diff --git a/TangramKitDemo/FloatLayoutDemo/FOLTest3ViewController.swift b/TangramKitDemo/FloatLayoutDemo/FOLTest3ViewController.swift index 1350b98..36159da 100644 --- a/TangramKitDemo/FloatLayoutDemo/FOLTest3ViewController.swift +++ b/TangramKitDemo/FloatLayoutDemo/FOLTest3ViewController.swift @@ -187,7 +187,7 @@ extension FOLTest3ViewController { - func handleChangeStyle(_ sender:AnyObject!) + @objc func handleChangeStyle(_ sender:AnyObject!) { //zaker的每页新闻中都有6条新闻,其中一条图片新闻和5条文字新闻。在布局上则高度分为5份,其中的图片新闻则占据了2/5,而高度则是全屏。 @@ -249,7 +249,7 @@ extension FOLTest3ViewController } - func handleItemLayoutClick(_ sender:UIView!) + @objc func handleItemLayoutClick(_ sender:UIView!) { let message = "You click:\(sender.tag)" UIAlertView(title: nil, message: message, delegate: nil, cancelButtonTitle: "OK").show() diff --git a/TangramKitDemo/FloatLayoutDemo/FOLTest4ViewController.swift b/TangramKitDemo/FloatLayoutDemo/FOLTest4ViewController.swift index 4fe53a5..34773a8 100644 --- a/TangramKitDemo/FloatLayoutDemo/FOLTest4ViewController.swift +++ b/TangramKitDemo/FloatLayoutDemo/FOLTest4ViewController.swift @@ -323,7 +323,7 @@ extension FOLTest4ViewController //MARK: Handle Method extension FOLTest4ViewController { - func handleTagViewTap(sender:UIView!) + @objc func handleTagViewTap(sender:UIView!) { let partIndex = sender.tag / 1000 / 1000; let sectionIndex = (sender.tag / 1000) % 1000; @@ -335,7 +335,7 @@ extension FOLTest4ViewController } - func handleSectionViewTap(sender:UIView!) + @objc func handleSectionViewTap(sender:UIView!) { let partIndex = sender.tag / 1000; let sectionIndex = sender.tag % 1000; @@ -345,7 +345,7 @@ extension FOLTest4ViewController } - func handleStyleChange(sender:UIButton!) + @objc func handleStyleChange(sender:UIButton!) { self.contentLayout.subviews.forEach {$0.removeFromSuperview()} diff --git a/TangramKitDemo/FlowLayoutDemo/FLLTest1ViewController.swift b/TangramKitDemo/FlowLayoutDemo/FLLTest1ViewController.swift index 6f7d823..4a75112 100644 --- a/TangramKitDemo/FlowLayoutDemo/FLLTest1ViewController.swift +++ b/TangramKitDemo/FlowLayoutDemo/FLLTest1ViewController.swift @@ -125,7 +125,7 @@ extension FLLTest1ViewController //MARK: -Handle Method extension FLLTest1ViewController { - func handleAdjustOrientation(_ sender:AnyObject?) + @objc func handleAdjustOrientation(_ sender:AnyObject?) { //调整流式布局的方向。 if (self.flowLayout.tg_orientation == .vert) @@ -143,7 +143,7 @@ extension FLLTest1ViewController } - func handleAdjustArrangedCount(_ sender:AnyObject?) + @objc func handleAdjustArrangedCount(_ sender:AnyObject?) { //调整流式布局的每行的数量。 @@ -154,7 +154,7 @@ extension FLLTest1ViewController } - func handleAdjustVertGravity(_ sender:AnyObject?) + @objc func handleAdjustVertGravity(_ sender:AnyObject?) { //调整整体垂直方向的停靠 @@ -196,7 +196,7 @@ extension FLLTest1ViewController - func handleAdjustHorzGravity(_ sender:AnyObject?) + @objc func handleAdjustHorzGravity(_ sender:AnyObject?) { //调整整体水平方向的停靠。 @@ -237,7 +237,7 @@ extension FLLTest1ViewController } - func handleAdjustArrangeGravity(_ sender:AnyObject?) + @objc func handleAdjustArrangeGravity(_ sender:AnyObject?) { var vertArrangeGravity = self.flowLayout.tg_arrangedGravity & TGGravity.horz.mask var horzArrangeGravity = self.flowLayout.tg_arrangedGravity & TGGravity.vert.mask @@ -301,7 +301,7 @@ extension FLLTest1ViewController self.flowlayoutInfo() } - func handleAdjustSpace(_ sender:AnyObject?) + @objc func handleAdjustSpace(_ sender:AnyObject?) { //调整子视图之间的间距 diff --git a/TangramKitDemo/FlowLayoutDemo/FLLTest2ViewController.swift b/TangramKitDemo/FlowLayoutDemo/FLLTest2ViewController.swift index 2f4f27b..06c471f 100644 --- a/TangramKitDemo/FlowLayoutDemo/FLLTest2ViewController.swift +++ b/TangramKitDemo/FlowLayoutDemo/FLLTest2ViewController.swift @@ -142,7 +142,7 @@ extension FLLTest2ViewController } - func handleAddTag(sender:Any!) + @objc func handleAddTag(sender:Any!) { if let text = self.tagTextField.text { @@ -154,7 +154,7 @@ extension FLLTest2ViewController } } - func handleStretchSpace(sender:UISwitch!) + @objc func handleStretchSpace(sender:UISwitch!) { //间距拉伸 @@ -170,7 +170,7 @@ extension FLLTest2ViewController self.flowLayout.tg_layoutAnimationWithDuration(0.2) } - func handleStretchContent(sender:UISwitch!) + @objc func handleStretchContent(sender:UISwitch!) { //内容拉伸 @@ -187,7 +187,7 @@ extension FLLTest2ViewController } - func handleAutoArrange(sender:UISwitch!) + @objc func handleAutoArrange(sender:UISwitch!) { //自动调整位置。 @@ -204,7 +204,7 @@ extension FLLTest2ViewController } - func handleDelTag(sender:UIButton!) + @objc func handleDelTag(sender:UIButton!) { sender.removeFromSuperview() self.flowLayout.tg_layoutAnimationWithDuration(0.2) diff --git a/TangramKitDemo/FlowLayoutDemo/FLLTest3ViewController.swift b/TangramKitDemo/FlowLayoutDemo/FLLTest3ViewController.swift index 4a6363e..b966bbd 100644 --- a/TangramKitDemo/FlowLayoutDemo/FLLTest3ViewController.swift +++ b/TangramKitDemo/FlowLayoutDemo/FLLTest3ViewController.swift @@ -90,8 +90,10 @@ class FLLTest3ViewController: UIViewController { tagButton.backgroundColor = UIColor(red: CGFloat(arc4random()%256)/255.0, green: CGFloat(arc4random()%256)/255.0, blue: CGFloat(arc4random()%256)/255.0, alpha: 1.0) tagButton.tg_height.equal(44) tagButton.addTarget(self, action: #selector(handleTouchDrag(sender:event:)), for: .touchDragInside) //注册拖动事件。 + tagButton.addTarget(self, action: #selector(handleTouchDrag(sender:event:)), for: .touchDragOutside) //注册拖动事件。 tagButton.addTarget(self, action: #selector(handleTouchDown(sender:event:)), for: .touchDown) //注册按下事件 tagButton.addTarget(self, action: #selector(handleTouchUp), for: .touchUpInside) //注册抬起事件 + tagButton.addTarget(self, action: #selector(handleTouchUp), for: .touchCancel) //注册抬起事件 tagButton.addTarget(self, action: #selector(handleTouchDownRepeat(sender:event:)), for: .touchDownRepeat) //注册多次点击事件 return tagButton; } @@ -114,13 +116,13 @@ class FLLTest3ViewController: UIViewController { extension FLLTest3ViewController { - func handleAddTagButton(sender: AnyObject) + @objc func handleAddTagButton(sender: AnyObject) { let label = NSLocalizedString("drag me \(self.flowLayout.subviews.count-1)", comment: "") self.flowLayout.insertSubview(self.createTagButton(text: label), at: self.flowLayout.subviews.count-1) } - func handleTouchDrag(sender: UIButton, event: UIEvent) { + @objc func handleTouchDrag(sender: UIButton, event: UIEvent) { self.hasDrag = true //取出拖动时当前的位置点。 @@ -180,7 +182,7 @@ extension FLLTest3ViewController { sender.center = pt //因为tg_useFrame设置为了YES所有这里可以直接调整center,从而实现了位置的自定义设置。 } - func handleTouchDown(sender: UIButton, event: UIEvent) + @objc func handleTouchDown(sender: UIButton, event: UIEvent) { //在按下时记录当前要拖动的控件的索引。 self.oldIndex = self.flowLayout.subviews.index(of: sender)! @@ -188,7 +190,7 @@ extension FLLTest3ViewController { self.hasDrag = false } - func handleTouchUp(sender: UIButton, event: UIEvent) { + @objc func handleTouchUp(sender: UIButton, event: UIEvent) { if !self.hasDrag { return } @@ -206,7 +208,7 @@ extension FLLTest3ViewController { } - func handleTouchDownRepeat(sender: UIButton, event: UIEvent) { + @objc func handleTouchDownRepeat(sender: UIButton, event: UIEvent) { sender.removeFromSuperview() self.flowLayout.tg_layoutAnimationWithDuration(0.2) } diff --git a/TangramKitDemo/FlowLayoutDemo/FLLTest6ViewController.swift b/TangramKitDemo/FlowLayoutDemo/FLLTest6ViewController.swift index 306fb04..a74789a 100644 --- a/TangramKitDemo/FlowLayoutDemo/FLLTest6ViewController.swift +++ b/TangramKitDemo/FlowLayoutDemo/FLLTest6ViewController.swift @@ -60,7 +60,7 @@ class FLLTest6ViewController: UIViewController { } - func handleTap(sender:UIButton!) + @objc func handleTap(sender:UIButton!) { //这里实现单击里面控件按钮来实现多行多列到单行单列的切换。多行多列时布局视图的宽度和父视图相等,而单行单列时布局视图的高度和父视图的高度相等。 //下面这段话就是用来设置每次切换时的布局尺寸的处理。 diff --git a/TangramKitDemo/Info.plist b/TangramKitDemo/Info.plist index 0c77525..0d5ca27 100644 --- a/TangramKitDemo/Info.plist +++ b/TangramKitDemo/Info.plist @@ -17,13 +17,17 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.1.1 + 1.1.2 CFBundleSignature ???? CFBundleVersion 1 LSRequiresIPhoneOS + UIBackgroundModes + + remote-notification + UILaunchStoryboardName LaunchScreen UIRequiredDeviceCapabilities diff --git a/TangramKitDemo/IntegratedDemo/AllTest1ViewController.swift b/TangramKitDemo/IntegratedDemo/AllTest1ViewController.swift index 0480793..e6a1e19 100644 --- a/TangramKitDemo/IntegratedDemo/AllTest1ViewController.swift +++ b/TangramKitDemo/IntegratedDemo/AllTest1ViewController.swift @@ -26,8 +26,8 @@ class AllTest1ViewController: UITableViewController { let textMessages = ["", NSLocalizedString("a single line text", comment:""), - NSLocalizedString("This Demo is used to introduce the solution when use layout view to realize the UITableViewCell's dynamic height. We only need to use the layout view's estimateLayoutRect method to evaluate the size of the layout view. and you can touch the Cell to shrink the height when the Cell has a picture.", comment:""), - NSLocalizedString("Through layout view's estimateLayoutRect method can assess a UITableViewCell dynamic height.EstimateLayoutRect just to evaluate layout size but not set the size of the layout. here don't preach the width of 0 is the cause of the above UITableViewCell set the default width is 320 (regardless of any screen), so if we pass the width of 0 will be according to the width of 320 to evaluate UITableViewCell dynamic height, so when in 375 and 375 the width of the assessment of height will not be right, so here you need to specify the real width dimension;And the height is set to 0 mean height is not a fixed value need to evaluate. you can use all type layout view to realize UITableViewCell.", comment:""), + NSLocalizedString("This Demo is used to introduce the solution when use layout view to realize the UITableViewCell's dynamic height. We only need to use the layout view's tg_sizeThatFits method to evaluate the size of the layout view. and you can touch the Cell to shrink the height when the Cell has a picture.", comment:""), + NSLocalizedString("Through layout view's tg_sizeThatFits method can assess a UITableViewCell dynamic height.tg_sizeThatFits just to evaluate layout size but not set the size of the layout. here don't preach the width of 0 is the cause of the above UITableViewCell set the default width is 320 (regardless of any screen), so if we pass the width of 0 will be according to the width of 320 to evaluate UITableViewCell dynamic height, so when in 375 and 375 the width of the assessment of height will not be right, so here you need to specify the real width dimension;And the height is set to 0 mean height is not a fixed value need to evaluate. you can use all type layout view to realize UITableViewCell.", comment:""), NSLocalizedString("This section not only has text but also hav picture. and picture below at text, text will wrap", comment:"") ] @@ -53,7 +53,7 @@ class AllTest1ViewController: UITableViewController { var displayLink:CADisplayLink!=nil; var count:Int = 0 var lastTime:TimeInterval = 0.0 - func tick(sender:CADisplayLink) + @objc func tick(sender:CADisplayLink) { if (self.lastTime == 0) { @@ -314,7 +314,7 @@ class AllTest1ViewController: UITableViewController { } - func handleTableHeaderViewLayoutClick(sender:TGBaseLayout!) + @objc func handleTableHeaderViewLayoutClick(sender:TGBaseLayout!) { if let label1 = sender.viewWithTag(1000) { diff --git a/TangramKitDemo/IntegratedDemo/AllTest2ViewController.swift b/TangramKitDemo/IntegratedDemo/AllTest2ViewController.swift index e8b6d43..49a7781 100644 --- a/TangramKitDemo/IntegratedDemo/AllTest2ViewController.swift +++ b/TangramKitDemo/IntegratedDemo/AllTest2ViewController.swift @@ -25,7 +25,7 @@ class AllTest2ViewController: UITableViewController { let names = ["欧阳大哥","醉里挑灯看键","张三","尼古拉・阿列克赛耶维奇・奥斯特洛夫斯基"] let descs = ["只有一行文本", "这个例子是用于测试自动布局在UITableView中实现静态高度的解决方案。", - "通过布局视图的estimateLayoutRect函数能够评估出UITableViewCell的动态高度", + "通过布局视图的tg_sizeThatFits函数能够评估出UITableViewCell的动态高度", "这是一段既有文本也有图片,文本在上面,图片在下面" ] diff --git a/TangramKitDemo/IntegratedDemo/AllTest3ViewController.swift b/TangramKitDemo/IntegratedDemo/AllTest3ViewController.swift index 149e398..0e1852c 100644 --- a/TangramKitDemo/IntegratedDemo/AllTest3ViewController.swift +++ b/TangramKitDemo/IntegratedDemo/AllTest3ViewController.swift @@ -406,42 +406,42 @@ extension AllTest3ViewController extension AllTest3ViewController { - func handleTap(sender:TGBaseLayout) + @objc func handleTap(sender:TGBaseLayout) { UIAlertView(title:"test", message:"you touched this section", delegate:nil, cancelButtonTitle:"OK").show() } - func handleTouchDown(sender:TGBaseLayout) + @objc func handleTouchDown(sender:TGBaseLayout) { let label = sender.viewWithTag(1000) as! UILabel label.textColor = .blue print("按下动作") } - func handleTouchCancel(sender:TGBaseLayout) + @objc func handleTouchCancel(sender:TGBaseLayout) { let label = sender.viewWithTag(1000) as! UILabel label.textColor = .black print("按下取消") } - func handleResetShow(sender:UIButton) + @objc func handleResetShow(sender:UIButton) { self.invisibleButton.tg_visibility = .visible self.goneButton.tg_visibility = .visible } - func handleInvisible(sender:UIButton) + @objc func handleInvisible(sender:UIButton) { sender.tg_visibility = .invisible } - func handleGone(sender:UIButton) + @objc func handleGone(sender:UIButton) { sender.tg_visibility = .gone } - func handleLeftFlexed(segmented: UISegmentedControl) + @objc func handleLeftFlexed(segmented: UISegmentedControl) { if (segmented.selectedSegmentIndex == 0) @@ -468,7 +468,7 @@ extension AllTest3ViewController } - func handleRightFlexed(segmented: UISegmentedControl) { + @objc func handleRightFlexed(segmented: UISegmentedControl) { if segmented.selectedSegmentIndex == 0 { let strs = "01234567890" @@ -489,7 +489,7 @@ extension AllTest3ViewController } } - func handleShrinkSwitch(sender: UISwitch) { + @objc func handleShrinkSwitch(sender: UISwitch) { if sender.isOn { self.shrinkLayout.tg_height.equal(.wrap) } @@ -500,7 +500,7 @@ extension AllTest3ViewController self.shrinkLayout.tg_layoutAnimationWithDuration(0.3) } - func handleShowPopMenu(sender: TGBaseLayout) { + @objc func handleShowPopMenu(sender: TGBaseLayout) { if self.popmenuLayout != nil && self.popmenuLayout.superview != nil { @@ -599,7 +599,7 @@ extension AllTest3ViewController self.frameLayout.tg_layoutAnimationWithDuration(0.3) } - func handleAddMe(sender: UIButton) { + @objc func handleAddMe(sender: UIButton) { let button = UIButton() button.setTitle(NSLocalizedString("double tap remove:\(sender.superview!.subviews.count)", comment:""), for: .normal) @@ -620,7 +620,7 @@ extension AllTest3ViewController self.popmenuContainerLayout.tg_layoutAnimationWithDuration(0.3) } - func handleDelMe(sender: UIButton!) + @objc func handleDelMe(sender: UIButton!) { sender.removeFromSuperview() let size = self.popmenuItemLayout.tg_sizeThatFits() @@ -630,7 +630,7 @@ extension AllTest3ViewController self.popmenuContainerLayout.tg_layoutAnimationWithDuration(0.3) } - func handleClosePopmenu(sender: UIButton!) { + @objc func handleClosePopmenu(sender: UIButton!) { //因为popmenuLayout的设置会激发frameLayout的重新布局,所以这里用这个方法进行动画消失处理。 self.popmenuLayout.tg_top.equal(self.frameLayout.frame.size.height) UIView.animate(withDuration: 0.3, animations: { @@ -640,7 +640,7 @@ extension AllTest3ViewController }) } - func handleActiveTest(sender:UIButton!) + @objc func handleActiveTest(sender:UIButton!) { //下面代码中布局位置的active属性设置的变化所产生的效果。 if (sender.tg_leading.isActive && sender.tg_trailing.isActive) diff --git a/TangramKitDemo/IntegratedDemo/AllTest4ViewController.swift b/TangramKitDemo/IntegratedDemo/AllTest4ViewController.swift index d76d712..c30e3ab 100644 --- a/TangramKitDemo/IntegratedDemo/AllTest4ViewController.swift +++ b/TangramKitDemo/IntegratedDemo/AllTest4ViewController.swift @@ -171,7 +171,7 @@ extension AllTest4ViewController //MARK: - Handle Method extension AllTest4ViewController { - func handleReverse(_ sender:UIView) -> Void { + @objc func handleReverse(_ sender:UIView) -> Void { //TGBaseLayout的属性tg_reverseLayout可以将子视图按照添加的顺序逆序布局。 for layout in self.containerLayouts { @@ -231,7 +231,7 @@ extension AllTest4ViewController } - func handleCellLayoutTap(_ sender:UIView) -> Void { + @objc func handleCellLayoutTap(_ sender:UIView) -> Void { //这里是为了节省,所以将两个不同的功能放在一起。。。 diff --git a/TangramKitDemo/IntegratedDemo/AllTest7ViewController.swift b/TangramKitDemo/IntegratedDemo/AllTest7ViewController.swift index c06c247..9a22135 100644 --- a/TangramKitDemo/IntegratedDemo/AllTest7ViewController.swift +++ b/TangramKitDemo/IntegratedDemo/AllTest7ViewController.swift @@ -174,13 +174,13 @@ extension AllTest7ViewController } - func handleAdd(_ sender: UIButton) { + @objc func handleAdd(_ sender: UIButton) { let label1 = sender.superview!.viewWithTag(1000) as! UILabel label1.text = label1.text!.appending("/您好!") } - func handleDel(_ sender: UIButton) { + @objc func handleDel(_ sender: UIButton) { let label1 = sender.superview!.viewWithTag(1000) as! UILabel label1.text = "/您好!" @@ -241,7 +241,7 @@ extension AllTest7ViewController } - func handleChangeText(_ sender: UIButton) { + @objc func handleChangeText(_ sender: UIButton) { let texts = ["这是一段很长的文本,目的是为了实现最大限度的利用整个空间而不出现多余的缝隙","您好","北京市朝阳区三里屯SOHO城","我是醉里挑灯看键","欧阳大哥","Tangram是一套功能强大的综合界面布局库"] @@ -324,7 +324,7 @@ extension AllTest7ViewController * 下面这个DEMO实现子视图之间的间距压缩,来达到最完美的适配。 */ - func handleAddButton(_ sender: UIButton) { + @objc func handleAddButton(_ sender: UIButton) { let button = UIButton(type: .system) button.layer.cornerRadius = 6 button.layer.borderWidth = 0.5 @@ -337,7 +337,7 @@ extension AllTest7ViewController sender.superview!.addSubview(button) } - func handleDelButton(_ sender: UIButton) { + @objc func handleDelButton(_ sender: UIButton) { sender.removeFromSuperview() } @@ -378,7 +378,7 @@ extension AllTest7ViewController * 下面这个DEMO实现子视图之间的尺寸压缩,来达到最完美的适配。 */ - func handleAddCell(_ sender: UIButton) { + @objc func handleAddCell(_ sender: UIButton) { //在创建时指定了6000.所以这里为了方便使用。 let tableLayout = sender.superview!.viewWithTag(6000) as! TGTableLayout let cellLabel = UILabel() diff --git a/TangramKitDemo/IntegratedDemo/AllTest8ViewController.swift b/TangramKitDemo/IntegratedDemo/AllTest8ViewController.swift index bc5ef27..c002461 100644 --- a/TangramKitDemo/IntegratedDemo/AllTest8ViewController.swift +++ b/TangramKitDemo/IntegratedDemo/AllTest8ViewController.swift @@ -131,7 +131,7 @@ class AllTest8ViewController: UIViewController { // Dispose of any resources that can be recreated. } - func handleDemo1AddTest(sender:UIButton!) + @objc func handleDemo1AddTest(sender:UIButton!) { if let label = sender.superview?.superview?.subviews[1] as? UILabel { @@ -140,14 +140,14 @@ class AllTest8ViewController: UIViewController { } - func handleDemo1RemoveLayout(sender:UIButton!) + @objc func handleDemo1RemoveLayout(sender:UIButton!) { UIView.perform(.delete, on: [sender.superview!.superview!], options: .curveLinear, animations: nil, completion: nil) } - func handleDemo1(sener:UIButton!) + @objc func handleDemo1(sener:UIButton!) { //布局视图用来实现弹框,这里把一个布局视图放入一个非布局视图里面。 let layout = TGLinearLayout(.vert) diff --git a/TangramKitDemo/IntegratedDemo/AllTestModel&View/AllTest1TableViewHeaderFooterView.swift b/TangramKitDemo/IntegratedDemo/AllTestModel&View/AllTest1TableViewHeaderFooterView.swift index 3771163..ff210fb 100644 --- a/TangramKitDemo/IntegratedDemo/AllTestModel&View/AllTest1TableViewHeaderFooterView.swift +++ b/TangramKitDemo/IntegratedDemo/AllTestModel&View/AllTest1TableViewHeaderFooterView.swift @@ -82,7 +82,7 @@ class AllTest1TableViewHeaderFooterView: UITableViewHeaderFooterView { } - func handleTap(_ sender: TGBaseLayout) { + @objc func handleTap(_ sender: TGBaseLayout) { switch sender.tag { case 0: self.underLineView.tg_leading.equal(0) diff --git a/TangramKitDemo/PathLayoutDemo/PLTest1ViewController.swift b/TangramKitDemo/PathLayoutDemo/PLTest1ViewController.swift index 6fa3e61..d7c4f22 100644 --- a/TangramKitDemo/PathLayoutDemo/PLTest1ViewController.swift +++ b/TangramKitDemo/PathLayoutDemo/PLTest1ViewController.swift @@ -23,6 +23,12 @@ class PLTest1ViewController: UIViewController { self.edgesForExtendedLayout = UIRectEdge(rawValue:0) //设置视图控制器中的视图尺寸不延伸到导航条或者工具条下面。您可以注释这句代码看看效果。 + //为了支持iPhoneX而设置附加的安全区缩进。否则根视图将延伸到工具栏下面去了。 + if #available(iOS 11.0, *) { + self.additionalSafeAreaInsets = UIEdgeInsetsMake(0, 0, 44, 0) + } else { + // Fallback on earlier versions + } myPathLayout = TGPathLayout() myPathLayout.backgroundColor = UIColor.white @@ -168,7 +174,7 @@ class PLTest1ViewController: UIViewController { // MARK: - Actions - func addAction() { + @objc func addAction() { let btn = UIButton(type: .custom) btn.center = myPathLayout.tg_originView!.center btn.tg_width.equal(40) @@ -182,7 +188,7 @@ class PLTest1ViewController: UIViewController { btn.addTarget(self, action: #selector(PLTest1ViewController.handleDrag(sender:)), for: .touchDragInside) } - func handleDel(sender: UIButton) { + @objc func handleDel(sender: UIButton) { sender.tg_useFrame = true UIView.animate(withDuration: 0.3, animations: { @@ -198,13 +204,13 @@ class PLTest1ViewController: UIViewController { myPathLayout.tg_layoutAnimationWithDuration(0.5) } - func handleDrag(sender: UIButton) { + @objc func handleDrag(sender: UIButton) { //这个效果只有在圆环中才有效果,你拖动时可以通过调整坐标的开始和结束点来很轻易的实现转动的效果。 myPathLayout.tg_coordinateSetting.start! += .pi/180.0 myPathLayout.tg_coordinateSetting.end! += .pi/180.0 } - func handleStretch1(sender: UIBarButtonItem) { + @objc func handleStretch1(sender: UIBarButtonItem) { guard let originView = myPathLayout.tg_originView else { return } @@ -253,7 +259,7 @@ class PLTest1ViewController: UIViewController { } } - func handleStretch2(sender: UIBarButtonItem) { + @objc func handleStretch2(sender: UIBarButtonItem) { guard let _ = myPathLayout.tg_originView else { return } @@ -315,7 +321,7 @@ class PLTest1ViewController: UIViewController { } - func handleCircle(sender: UIBarButtonItem) { + @objc func handleCircle(sender: UIBarButtonItem) { toolbarItems?[0].style = .done toolbarItems?[1].style = .plain toolbarItems?[2].style = .plain @@ -327,7 +333,7 @@ class PLTest1ViewController: UIViewController { myPathLayout.tg_layoutAnimationWithDuration(0.5) } - func handleArc(sender: UIBarButtonItem) { + @objc func handleArc(sender: UIBarButtonItem) { toolbarItems?[0].style = .plain toolbarItems?[1].style = .done toolbarItems?[2].style = .plain @@ -339,7 +345,7 @@ class PLTest1ViewController: UIViewController { myPathLayout.tg_layoutAnimationWithDuration(0.5) } - func handleArc2(sender: UIBarButtonItem) { + @objc func handleArc2(sender: UIBarButtonItem) { toolbarItems?[0].style = .plain toolbarItems?[1].style = .plain toolbarItems?[2].style = .done @@ -351,7 +357,7 @@ class PLTest1ViewController: UIViewController { myPathLayout.tg_layoutAnimationWithDuration(0.5) } - func handleLine1(sender: UIBarButtonItem) { + @objc func handleLine1(sender: UIBarButtonItem) { toolbarItems?[0].style = .plain toolbarItems?[1].style = .plain toolbarItems?[2].style = .plain @@ -363,7 +369,7 @@ class PLTest1ViewController: UIViewController { myPathLayout.tg_layoutAnimationWithDuration(0.5) } - func handleLine2(sender: UIBarButtonItem) { + @objc func handleLine2(sender: UIBarButtonItem) { toolbarItems?[0].style = .plain toolbarItems?[1].style = .plain toolbarItems?[2].style = .plain @@ -376,7 +382,7 @@ class PLTest1ViewController: UIViewController { } - func handleFlexed(sender: UIBarButtonItem) { + @objc func handleFlexed(sender: UIBarButtonItem) { toolbarItems?[6].style = .done toolbarItems?[7].style = .plain toolbarItems?[8].style = .plain @@ -385,7 +391,7 @@ class PLTest1ViewController: UIViewController { myPathLayout.tg_layoutAnimationWithDuration(0.5) } - func handleFixed(sender: UIBarButtonItem) { + @objc func handleFixed(sender: UIBarButtonItem) { toolbarItems?[6].style = .plain toolbarItems?[7].style = .done toolbarItems?[8].style = .plain @@ -394,7 +400,7 @@ class PLTest1ViewController: UIViewController { myPathLayout.tg_layoutAnimationWithDuration(0.5) } - func handleCount(sender: UIBarButtonItem) { + @objc func handleCount(sender: UIBarButtonItem) { toolbarItems?[6].style = .plain toolbarItems?[7].style = .plain toolbarItems?[8].style = .done diff --git a/TangramKitDemo/PathLayoutDemo/PLTest2ViewController.swift b/TangramKitDemo/PathLayoutDemo/PLTest2ViewController.swift index 3a2f568..ce72755 100644 --- a/TangramKitDemo/PathLayoutDemo/PLTest2ViewController.swift +++ b/TangramKitDemo/PathLayoutDemo/PLTest2ViewController.swift @@ -69,7 +69,7 @@ class PLTest2ViewController: UIViewController { changeFunc(index: .straight_line) } - func handleRevrse(sender: UIBarButtonItem) { + @objc func handleRevrse(sender: UIBarButtonItem) { myPathLayout.tg_coordinateSetting.isReverse = !myPathLayout.tg_coordinateSetting.isReverse myPathLayout.tg_layoutAnimationWithDuration(0.3) } @@ -86,7 +86,7 @@ class PLTest2ViewController: UIViewController { let titles: [CurveType] = [.straight_line, .sin, .cycloid, .spiral_like, .cardioid, .astroid, .cancle] - func handleAction(sender: UIBarButtonItem) { + @objc func handleAction(sender: UIBarButtonItem) { let sheet = UIAlertController(title: "Curve Type", message: nil, preferredStyle: .actionSheet) @@ -129,7 +129,7 @@ class PLTest2ViewController: UIViewController { return colors[Int(arc4random_uniform(UInt32(colors.count)))] } - func handleAdd(sender: UIBarButtonItem) { + @objc func handleAdd(sender: UIBarButtonItem) { var pt = CGPoint.zero if myPathLayout.tg_pathSubviews.count > 0 { @@ -151,7 +151,7 @@ class PLTest2ViewController: UIViewController { myPathLayout.tg_layoutAnimationWithDuration(0.3) } - func handleDel(sender: UIButton) { + @objc func handleDel(sender: UIButton) { sender.removeFromSuperview() myPathLayout.tg_layoutAnimationWithDuration(0.3) } diff --git a/TangramKitDemo/PathLayoutDemo/PLTest3ViewController.swift b/TangramKitDemo/PathLayoutDemo/PLTest3ViewController.swift index f004650..96da05b 100644 --- a/TangramKitDemo/PathLayoutDemo/PLTest3ViewController.swift +++ b/TangramKitDemo/PathLayoutDemo/PLTest3ViewController.swift @@ -130,7 +130,7 @@ class PLTest3ViewController: UIViewController { // Do any additional setup after loading the view. } - func handleClick(sender: UIButton) { + @objc func handleClick(sender: UIButton) { //例子中一共有7个子视图。因此每次旋转都是增加 360 / 7度。如果您要实现拖拽进行调整位置时,也只需要动态改变坐标的开始和结束位置就可以了。 myPathLayout.tg_coordinateSetting.start! += 2 * CGFloat.pi / CGFloat(myPathLayout.tg_pathSubviews.count) diff --git a/TangramKitDemo/PathLayoutDemo/PLTest4ViewController.swift b/TangramKitDemo/PathLayoutDemo/PLTest4ViewController.swift index 9c58919..8f05df2 100644 --- a/TangramKitDemo/PathLayoutDemo/PLTest4ViewController.swift +++ b/TangramKitDemo/PathLayoutDemo/PLTest4ViewController.swift @@ -71,7 +71,7 @@ class PLTest4ViewController: UIViewController { } - func handleAction(sender: UIButton) { + @objc func handleAction(sender: UIButton) { if sender.isSelected { diff --git a/TangramKitDemo/RelativeLayoutDemo/RLTest2ViewController.swift b/TangramKitDemo/RelativeLayoutDemo/RLTest2ViewController.swift index a0602e5..7d70d09 100644 --- a/TangramKitDemo/RelativeLayoutDemo/RLTest2ViewController.swift +++ b/TangramKitDemo/RelativeLayoutDemo/RLTest2ViewController.swift @@ -194,7 +194,7 @@ class RLTest2ViewController: UIViewController { extension RLTest2ViewController { - func handleHidden(_ sender: UIButton) { + @objc func handleHidden(_ sender: UIButton) { if self.visibilitySwitch.isOn { @@ -207,7 +207,7 @@ extension RLTest2ViewController } - func handleShow(_ sender: UIButton) { + @objc func handleShow(_ sender: UIButton) { self.visibilityButton.tg_visibility = .visible } diff --git a/TangramKitDemo/RelativeLayoutDemo/RLTest5ViewController.swift b/TangramKitDemo/RelativeLayoutDemo/RLTest5ViewController.swift index 8ff75a2..c0f0542 100644 --- a/TangramKitDemo/RelativeLayoutDemo/RLTest5ViewController.swift +++ b/TangramKitDemo/RelativeLayoutDemo/RLTest5ViewController.swift @@ -45,7 +45,7 @@ class RLTest5ViewController: UIViewController { } - func handleButtonSelect(_ button: UIButton) { + @objc func handleButtonSelect(_ button: UIButton) { if button.isSelected { return } @@ -182,7 +182,7 @@ class RLTest5ViewController: UIViewController { } - func handleClick(_ sender: UITapGestureRecognizer) { + @objc func handleClick(_ sender: UITapGestureRecognizer) { let label = (sender.view as! UILabel) let text = label.text diff --git a/TangramKitDemo/Support Files/zh-Hans.lproj/Localizable.strings b/TangramKitDemo/Support Files/zh-Hans.lproj/Localizable.strings index fcdad17..86d26c7 100644 --- a/TangramKitDemo/Support Files/zh-Hans.lproj/Localizable.strings +++ b/TangramKitDemo/Support Files/zh-Hans.lproj/Localizable.strings @@ -213,9 +213,9 @@ "the layoutIfNeeded is not need to call when you use frame to set layout view's size"="如果通过frame设置了明确的尺寸则不需要调用layoutIfNeeded"; "A single line text"="只有一行文本"; -"This Demo is used to introduce the solution when use layout view to realize the UITableViewCell's dynamic height. We only need to use the layout view's estimateLayoutRect method to evaluate the size of the layout view. and you can touch the Cell to shrink the height when the Cell has a picture."="这个例子用于介绍布局视图实现UITableViewCell动态高度的解决方案。我们只需要使用布局视图的estimateLayoutRect方法就可以对布局视图的尺寸进行评估。同时您可以在有图片的Cell中触摸查看自动伸缩的场景。"; +"This Demo is used to introduce the solution when use layout view to realize the UITableViewCell's dynamic height. We only need to use the layout view's tg_sizeThatFits method to evaluate the size of the layout view. and you can touch the Cell to shrink the height when the Cell has a picture."="这个例子用于介绍布局视图实现UITableViewCell动态高度的解决方案。我们只需要使用布局视图的tg_sizeThatFits方法就可以对布局视图的尺寸进行评估。同时您可以在有图片的Cell中触摸查看自动伸缩的场景。"; -"Through layout view's estimateLayoutRect method can assess a UITableViewCell dynamic height.EstimateLayoutRect just to evaluate layout size but not set the size of the layout. here don't preach the width of 0 is the cause of the above UITableViewCell set the default width is 320 (regardless of any screen), so if we pass the width of 0 will be according to the width of 320 to evaluate UITableViewCell dynamic height, so when in 375 and 375 the width of the assessment of height will not be right, so here you need to specify the real width dimension;And the height is set to 0 mean height is not a fixed value need to evaluate. you can use all type layout view to realize UITableViewCell."="通过布局视图的estimateLayoutRect函数能够评估出UITableViewCell的动态高度。estimateLayoutRect并不会进行布局而只是评估布局的尺寸,这里的宽度不传0的原因是上面的UITableViewCell在建立时默认的宽度是320(不管任何尺寸都如此),因此如果我们传递了宽度为0的话则会按320的宽度来评估UITableViewCell的动态高度,这样当在375和414的宽度时评估出来的高度将不会正确,因此这里需要指定出真实的宽度尺寸;而高度设置为0的意思是表示高度不是固定值需要评估出来。UITableViewCell的动态高度评估不局限于线性布局,其他布局也是同样适用。"; +"Through layout view's tg_sizeThatFits method can assess a UITableViewCell dynamic height.tg_sizeThatFits just to evaluate layout size but not set the size of the layout. here don't preach the width of 0 is the cause of the above UITableViewCell set the default width is 320 (regardless of any screen), so if we pass the width of 0 will be according to the width of 320 to evaluate UITableViewCell dynamic height, so when in 375 and 375 the width of the assessment of height will not be right, so here you need to specify the real width dimension;And the height is set to 0 mean height is not a fixed value need to evaluate. you can use all type layout view to realize UITableViewCell."="通过布局视图的tg_sizeThatFits函数能够评估出UITableViewCell的动态高度。tg_sizeThatFits并不会进行布局而只是评估布局的尺寸,这里的宽度不传0的原因是上面的UITableViewCell在建立时默认的宽度是320(不管任何尺寸都如此),因此如果我们传递了宽度为0的话则会按320的宽度来评估UITableViewCell的动态高度,这样当在375和414的宽度时评估出来的高度将不会正确,因此这里需要指定出真实的宽度尺寸;而高度设置为0的意思是表示高度不是固定值需要评估出来。UITableViewCell的动态高度评估不局限于线性布局,其他布局也是同样适用。"; "This section not only has text but also hav picture. and picture below at text, text will wrap"="这是一段既有文本也有图片,文本在上面,图片在下面。文本会自动的进行换行,而图片则在文本下面居中显示"; diff --git a/TangramKitDemo/TableLayoutDemo/TLTest1ViewController.swift b/TangramKitDemo/TableLayoutDemo/TLTest1ViewController.swift index 466da33..dd1853e 100644 --- a/TangramKitDemo/TableLayoutDemo/TLTest1ViewController.swift +++ b/TangramKitDemo/TableLayoutDemo/TLTest1ViewController.swift @@ -115,20 +115,34 @@ class TLTest1ViewController: UIViewController { colView = self.createLabel("Cell41", backgroundColor: CFTool.color(2)) tableLayout.tg_addCol(colView, inRow:4) - //第六行高度由子视图的高度决定,列均分宽度 - _ = tableLayout.tg_addRow(size:TGLayoutSize.wrap, colSize:TGLayoutSize.average) + + //第六行高度固定为30, 列数固定为4。这里只添加了3列,可见列宽是固定的。 + _ = tableLayout.tg_addRow(size:30, colCount:4) colView = self.createLabel("Cell50", backgroundColor: CFTool.color(1)) - colView.tg_height.equal(80) tableLayout.tg_addCol(colView, inRow:5) colView = self.createLabel("Cell51", backgroundColor: CFTool.color(2)) - colView.tg_height.equal(120) tableLayout.tg_addCol(colView, inRow:5) colView = self.createLabel("Cell52", backgroundColor: CFTool.color(3)) - colView.tg_height.equal(70) tableLayout.tg_addCol(colView, inRow:5) + + + //第七行高度由子视图的高度决定,列均分宽度 + _ = tableLayout.tg_addRow(size:TGLayoutSize.wrap, colSize:TGLayoutSize.average) + + colView = self.createLabel("Cell60", backgroundColor: CFTool.color(1)) + colView.tg_height.equal(80) + tableLayout.tg_addCol(colView, inRow:6) + + colView = self.createLabel("Cell61", backgroundColor: CFTool.color(2)) + colView.tg_height.equal(120) + tableLayout.tg_addCol(colView, inRow:6) + + colView = self.createLabel("Cell62", backgroundColor: CFTool.color(3)) + colView.tg_height.equal(70) + tableLayout.tg_addCol(colView, inRow:6) } diff --git a/TangramKitDemo/TableLayoutDemo/TLTest2ViewController.swift b/TangramKitDemo/TableLayoutDemo/TLTest2ViewController.swift index 03ed663..3d04e7a 100644 --- a/TangramKitDemo/TableLayoutDemo/TLTest2ViewController.swift +++ b/TangramKitDemo/TableLayoutDemo/TLTest2ViewController.swift @@ -101,7 +101,7 @@ extension TLTest2ViewController extension TLTest2ViewController { - func handleAddColLayout(_ sender:AnyObject?) + @objc func handleAddColLayout(_ sender:AnyObject?) { //获取表格布局中的每行的高度,找到高度最小的一行,如果高度都相等则选择索引号小的行。 var minHeight:CGFloat = CGFloat.greatestFiniteMagnitude @@ -138,7 +138,7 @@ extension TLTest2ViewController self.rootLayout.tg_addCol(colLayout, inRow:rowIndex) } - func handleColLayoutTap(sender:UIView!) + @objc func handleColLayoutTap(sender:UIView!) { let alertView = UIAlertView(title:"", message: String(format:NSLocalizedString("cell:%03ld be selected", comment:""), sender.tag), delegate: nil, cancelButtonTitle: "OK") diff --git a/TangramKitDemo/TableLayoutDemo/TLTest3ViewController.swift b/TangramKitDemo/TableLayoutDemo/TLTest3ViewController.swift index 7f94ce5..42344ff 100644 --- a/TangramKitDemo/TableLayoutDemo/TLTest3ViewController.swift +++ b/TangramKitDemo/TableLayoutDemo/TLTest3ViewController.swift @@ -160,7 +160,7 @@ extension TLTest3ViewController //MARK: - Handle Method extension TLTest3ViewController { - func handleCellTap(sender:TGBaseLayout) + @objc func handleCellTap(sender:TGBaseLayout) { let label = sender.subviews.first as! UILabel let message = "您单击了:\(label.text!)" @@ -168,7 +168,7 @@ extension TLTest3ViewController alert.show() } - func handleSpace(sender:Any?) + @objc func handleSpace(sender:Any?) { //执行间距调整的逻辑。 if self.rootLayout.tg_vspace == 0 diff --git a/TangramKitDemo/ViewController.swift b/TangramKitDemo/ViewController.swift index c6fd346..659e047 100644 --- a/TangramKitDemo/ViewController.swift +++ b/TangramKitDemo/ViewController.swift @@ -18,8 +18,7 @@ class ViewController: UITableViewController { super.viewDidLoad() self.title = NSLocalizedString("Category",comment:"") - self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName:CFTool.font(15),NSForegroundColorAttributeName:CFTool.color(4)] - + self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "test") let tipLabel = UILabel(frame:CGRect(x:0, y:0, width:0, height:50)) @@ -173,7 +172,7 @@ class ViewController: UITableViewController { // MARK: - Handle Method - func handleRTL(_ sender:UIBarButtonItem) + @objc func handleRTL(_ sender:UIBarButtonItem) { if TGBaseLayout.tg_isRTL diff --git a/TangramKitDemo/linerLayoutDemo/LLTest1ViewController.swift b/TangramKitDemo/linerLayoutDemo/LLTest1ViewController.swift index 88c0ca3..1a4c222 100644 --- a/TangramKitDemo/linerLayoutDemo/LLTest1ViewController.swift +++ b/TangramKitDemo/linerLayoutDemo/LLTest1ViewController.swift @@ -74,6 +74,19 @@ class LLTest1ViewController: UIViewController { let rootLayout = TGLinearLayout(.vert) rootLayout.backgroundColor = .white self.view = rootLayout; + + + + //为了支持iPhoneX的全屏幕适配。我们只需要对根布局视图设置一些扩展的属性,默认情况下是不需要进行特殊设置的,TangramKit自动会对iPhoneX进行适配 + //我们知道iOS11中引入了安全区域的概念,TangramKit中的根布局视图会自动将安全区域叠加到设置的padding中去。这个属性是通过tg_insetsPaddingFromSafeArea来完成的。 + //默认情况下四周的安全区域都会叠加到padding中去,因此您可以根据特殊情况来设置只需要叠加哪一个方向的安全区域。您可以通过如下的方法: + rootLayout.tg_insetsPaddingFromSafeArea = .all //您可以在这里将值改变为UIRectEdge的其他类型然后试试运行的效果。并且在运行时切换横竖屏看看效果 + + //iPhoneX设备中具有一个尺寸为44的刘海区域。当您横屏时为了对齐,左右两边的安全缩进区域都是44。但是有些时候我们希望没有刘海的那一边不需要缩进对齐而是延伸到安全区域以外。这时候您可以通过给根布局视图设置tg_insetLandscapeFringePadding属性来达到效果。 + //注意这个属性只有tg_insetsPaddingFromSafeArea设置了左右都缩进时才有效。 + rootLayout.tg_insetLandscapeFringePadding = false //您可以在横屏下将这个属性设置为true后,然后尝试一下进行左右旋转后查看运行的效果。 + + //下面的例子中vertLayout是一个垂直线性布局,垂直线性布局中的子视图按照添加的顺序依次从上到下排列。 diff --git a/TangramKitDemo/linerLayoutDemo/LLTest2ViewController.swift b/TangramKitDemo/linerLayoutDemo/LLTest2ViewController.swift index c73f0d7..6a05227 100644 --- a/TangramKitDemo/linerLayoutDemo/LLTest2ViewController.swift +++ b/TangramKitDemo/linerLayoutDemo/LLTest2ViewController.swift @@ -445,7 +445,7 @@ extension LLTest2ViewController // MARK: - Handle Method extension LLTest2ViewController { - func handleLabelShrink(_ sender :UIButton) + @objc func handleLabelShrink(_ sender :UIButton) { //如果当前高度是包裹值,则设置为0让高度变为0,否则再设置为.wrap。这样实现文本的高度伸缩。 @@ -461,7 +461,7 @@ extension LLTest2ViewController self.contentLayout.tg_layoutAnimationWithDuration(0.3) //设置完成布局中子视图的属性后可以调用布局视图的这个方法来实现动画效果。 } - func handleShowMore(_ sender: UIButton) + @objc func handleShowMore(_ sender: UIButton) { //布局里面,如果子视图被隐藏则会引起布局视图的自动布局。 if self.hiddenView.tg_visibility == .visible diff --git a/TangramKitDemo/linerLayoutDemo/LLTest3ViewController.swift b/TangramKitDemo/linerLayoutDemo/LLTest3ViewController.swift index b581aa8..ba8b25e 100644 --- a/TangramKitDemo/linerLayoutDemo/LLTest3ViewController.swift +++ b/TangramKitDemo/linerLayoutDemo/LLTest3ViewController.swift @@ -300,7 +300,7 @@ extension LLTest3ViewController //MARK: - Handle Method extension LLTest3ViewController { - func handleVertLayoutGravity(_ button:UIButton) + @objc func handleVertLayoutGravity(_ button:UIButton) { //分别取出垂直和水平方向的停靠设置。 var vertGravity = self.vertGravityLayout.tg_gravity & TGGravity.horz.mask @@ -352,7 +352,7 @@ extension LLTest3ViewController } - func handleHorzLayoutGravity(_ button:UIButton) + @objc func handleHorzLayoutGravity(_ button:UIButton) { //分别取出垂直和水平方向的停靠设置。 var vertGravity = self.horzGravityLayout.tg_gravity & TGGravity.horz.mask @@ -406,7 +406,7 @@ extension LLTest3ViewController } - func handleNavigationTitleCentre(_ sender: AnyObject!) + @objc func handleNavigationTitleCentre(_ sender: AnyObject!) { let navigationItemLayout = TGLinearLayout(.vert) //通过TGGravity.horz.windowCenter的设置总是保证在窗口的中间而不是布局视图的中间。 @@ -434,7 +434,7 @@ extension LLTest3ViewController } - func handleNavigationTitleRestore(_ sender: AnyObject!) + @objc func handleNavigationTitleRestore(_ sender: AnyObject!) { let topLabel = UILabel() topLabel.text = NSLocalizedString("title not center in the screen", comment:"") diff --git a/TangramKitDemo/linerLayoutDemo/LLTest4ViewController.swift b/TangramKitDemo/linerLayoutDemo/LLTest4ViewController.swift index 06f2f66..99e7148 100644 --- a/TangramKitDemo/linerLayoutDemo/LLTest4ViewController.swift +++ b/TangramKitDemo/linerLayoutDemo/LLTest4ViewController.swift @@ -133,7 +133,7 @@ extension LLTest4ViewController //MARK: - Handle Method extension LLTest4ViewController { - internal func handleAction(_ sender :UIButton) + @objc internal func handleAction(_ sender :UIButton) { if (sender.tag == 100) { diff --git a/TangramKitDemo/linerLayoutDemo/LLTest6ViewController.swift b/TangramKitDemo/linerLayoutDemo/LLTest6ViewController.swift index 264e578..f5fb50b 100644 --- a/TangramKitDemo/linerLayoutDemo/LLTest6ViewController.swift +++ b/TangramKitDemo/linerLayoutDemo/LLTest6ViewController.swift @@ -152,7 +152,7 @@ class LLTest6ViewController: UIViewController , UITextViewDelegate { // MARK: Handle Method - func handleHideKeyboard(_ sender: AnyObject) + @objc func handleHideKeyboard(_ sender: AnyObject) { self.view.endEditing(true) } diff --git a/TangramKitDemo/linerLayoutDemo/LLTest7ViewController.swift b/TangramKitDemo/linerLayoutDemo/LLTest7ViewController.swift index 3b32bd7..fbbcfdf 100644 --- a/TangramKitDemo/linerLayoutDemo/LLTest7ViewController.swift +++ b/TangramKitDemo/linerLayoutDemo/LLTest7ViewController.swift @@ -141,7 +141,7 @@ extension LLTest7ViewController extension LLTest7ViewController { - func handleAction(_ sender: UIButton) + @objc func handleAction(_ sender: UIButton) { //恢复原来的设置。 let arr = self.testLayout.subviews;