diff --git a/JCFrameLayout.podspec b/JCFrameLayout.podspec index 47b8f34..c36ecfe 100644 --- a/JCFrameLayout.podspec +++ b/JCFrameLayout.podspec @@ -16,8 +16,8 @@ Pod::Spec.new do |s| # s.name = "JCFrameLayout" - s.version = "1.0.0" - s.summary = "完成了left,top,right,bottom,width,height,centerX,centerY这几个属性进行组合布局." + s.version = "2.0.3" + s.summary = "一款采用链式语法为视图做Frame布局的工具" # This description is used to generate tags and improve search results. # * Think: What does it do? Why did you write it? What is the focus? @@ -25,7 +25,7 @@ Pod::Spec.new do |s| # * Write the description between the DESC delimiters below. # * Finally, don't worry about the indent, CocoaPods strips it! s.description = <<-DESC - 这是详细描述,完成了left,top,right,bottom,width,height,centerX,centerY这几个属性进行组合布局. + 这是详情,一款采用链式语法为视图做Frame布局的工具 DESC s.homepage = "https://github.com/devjackcat/JCFrameLayout" diff --git a/JCFrameLayout.xcodeproj/project.pbxproj b/JCFrameLayout.xcodeproj/project.pbxproj index 36a8987..a71af2f 100644 --- a/JCFrameLayout.xcodeproj/project.pbxproj +++ b/JCFrameLayout.xcodeproj/project.pbxproj @@ -7,53 +7,28 @@ objects = { /* Begin PBXBuildFile section */ - 282FD7D41E895B5E00E17BFB /* MASCompositeConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7BE1E895B5E00E17BFB /* MASCompositeConstraint.m */; }; - 282FD7D51E895B5E00E17BFB /* MASConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7C11E895B5E00E17BFB /* MASConstraint.m */; }; - 282FD7D61E895B5E00E17BFB /* MASConstraintMaker.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7C31E895B5E00E17BFB /* MASConstraintMaker.m */; }; - 282FD7D71E895B5E00E17BFB /* MASLayoutConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7C51E895B5E00E17BFB /* MASLayoutConstraint.m */; }; - 282FD7D81E895B5E00E17BFB /* MASViewAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7C91E895B5E00E17BFB /* MASViewAttribute.m */; }; - 282FD7D91E895B5E00E17BFB /* MASViewConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7CB1E895B5E00E17BFB /* MASViewConstraint.m */; }; - 282FD7DA1E895B5E00E17BFB /* NSArray+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7CD1E895B5E00E17BFB /* NSArray+MASAdditions.m */; }; - 282FD7DB1E895B5E00E17BFB /* NSLayoutConstraint+MASDebugAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7D01E895B5E00E17BFB /* NSLayoutConstraint+MASDebugAdditions.m */; }; - 282FD7DC1E895B5E00E17BFB /* View+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7D21E895B5E00E17BFB /* View+MASAdditions.m */; }; 282FD7E71E895B6400E17BFB /* JCFrameMake.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7E01E895B6400E17BFB /* JCFrameMake.m */; }; 282FD7E81E895B6400E17BFB /* JCFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7E21E895B6400E17BFB /* JCFrame.m */; }; 282FD7E91E895B6400E17BFB /* UIView+JCFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7E41E895B6400E17BFB /* UIView+JCFrame.m */; }; 282FD7EA1E895B6400E17BFB /* UIView+JCFrameLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7E61E895B6400E17BFB /* UIView+JCFrameLayout.m */; }; - 282FD7ED1E895B6D00E17BFB /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 282FD7EC1E895B6D00E17BFB /* SecondViewController.m */; }; + 2836F33C1E8CE49400C9BE35 /* JCFrameAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 2836F33B1E8CE49400C9BE35 /* JCFrameAttribute.m */; }; + 2836F3411E8E3DBA00C9BE35 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2836F3401E8E3DBA00C9BE35 /* SecondViewController.m */; }; + 2836F3441E8E3DE900C9BE35 /* ExampleVC1.m in Sources */ = {isa = PBXBuildFile; fileRef = 2836F3431E8E3DE900C9BE35 /* ExampleVC1.m */; }; + 2836F3471E8E438200C9BE35 /* ExampleVC2.m in Sources */ = {isa = PBXBuildFile; fileRef = 2836F3461E8E438200C9BE35 /* ExampleVC2.m */; }; + 2865622F1E8FA0D100707580 /* DevTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2865622E1E8FA0D100707580 /* DevTest.m */; }; 28D22AE21E8911C9002245F9 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D22AE11E8911C9002245F9 /* main.m */; }; 28D22AE51E8911C9002245F9 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D22AE41E8911C9002245F9 /* AppDelegate.m */; }; 28D22AE81E8911C9002245F9 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D22AE71E8911C9002245F9 /* ViewController.m */; }; - 28D22AEB1E8911C9002245F9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 28D22AE91E8911C9002245F9 /* Main.storyboard */; }; 28D22AED1E8911C9002245F9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 28D22AEC1E8911C9002245F9 /* Assets.xcassets */; }; 28D22AF01E8911C9002245F9 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 28D22AEE1E8911C9002245F9 /* LaunchScreen.storyboard */; }; 28E5EAD51E8B84A000701A93 /* JCFrameExecutor.m in Sources */ = {isa = PBXBuildFile; fileRef = 28E5EAD41E8B84A000701A93 /* JCFrameExecutor.m */; }; + 28F35D6E1E8E468C0028340C /* ExampleVC3.m in Sources */ = {isa = PBXBuildFile; fileRef = 28F35D6D1E8E468C0028340C /* ExampleVC3.m */; }; + 28F35D711E8E470D0028340C /* ExampleVC4.m in Sources */ = {isa = PBXBuildFile; fileRef = 28F35D701E8E470D0028340C /* ExampleVC4.m */; }; + 28F35D741E8E4F2F0028340C /* ExampleVC5.m in Sources */ = {isa = PBXBuildFile; fileRef = 28F35D731E8E4F2F0028340C /* ExampleVC5.m */; }; + 28F35D761E8E5AB80028340C /* QQ20170331-173628.png in Resources */ = {isa = PBXBuildFile; fileRef = 28F35D751E8E5AB80028340C /* QQ20170331-173628.png */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 282FD7BD1E895B5E00E17BFB /* MASCompositeConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASCompositeConstraint.h; sourceTree = ""; }; - 282FD7BE1E895B5E00E17BFB /* MASCompositeConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASCompositeConstraint.m; sourceTree = ""; }; - 282FD7BF1E895B5E00E17BFB /* MASConstraint+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASConstraint+Private.h"; sourceTree = ""; }; - 282FD7C01E895B5E00E17BFB /* MASConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASConstraint.h; sourceTree = ""; }; - 282FD7C11E895B5E00E17BFB /* MASConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASConstraint.m; sourceTree = ""; }; - 282FD7C21E895B5E00E17BFB /* MASConstraintMaker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASConstraintMaker.h; sourceTree = ""; }; - 282FD7C31E895B5E00E17BFB /* MASConstraintMaker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASConstraintMaker.m; sourceTree = ""; }; - 282FD7C41E895B5E00E17BFB /* MASLayoutConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASLayoutConstraint.h; sourceTree = ""; }; - 282FD7C51E895B5E00E17BFB /* MASLayoutConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASLayoutConstraint.m; sourceTree = ""; }; - 282FD7C61E895B5E00E17BFB /* Masonry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Masonry.h; sourceTree = ""; }; - 282FD7C71E895B5E00E17BFB /* MASUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASUtilities.h; sourceTree = ""; }; - 282FD7C81E895B5E00E17BFB /* MASViewAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASViewAttribute.h; sourceTree = ""; }; - 282FD7C91E895B5E00E17BFB /* MASViewAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASViewAttribute.m; sourceTree = ""; }; - 282FD7CA1E895B5E00E17BFB /* MASViewConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASViewConstraint.h; sourceTree = ""; }; - 282FD7CB1E895B5E00E17BFB /* MASViewConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASViewConstraint.m; sourceTree = ""; }; - 282FD7CC1E895B5E00E17BFB /* NSArray+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MASAdditions.h"; sourceTree = ""; }; - 282FD7CD1E895B5E00E17BFB /* NSArray+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+MASAdditions.m"; sourceTree = ""; }; - 282FD7CE1E895B5E00E17BFB /* NSArray+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MASShorthandAdditions.h"; sourceTree = ""; }; - 282FD7CF1E895B5E00E17BFB /* NSLayoutConstraint+MASDebugAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+MASDebugAdditions.h"; sourceTree = ""; }; - 282FD7D01E895B5E00E17BFB /* NSLayoutConstraint+MASDebugAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+MASDebugAdditions.m"; sourceTree = ""; }; - 282FD7D11E895B5E00E17BFB /* View+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASAdditions.h"; sourceTree = ""; }; - 282FD7D21E895B5E00E17BFB /* View+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "View+MASAdditions.m"; sourceTree = ""; }; - 282FD7D31E895B5E00E17BFB /* View+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASShorthandAdditions.h"; sourceTree = ""; }; 282FD7DE1E895B6400E17BFB /* JCFrameLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JCFrameLayout.h; sourceTree = ""; }; 282FD7DF1E895B6400E17BFB /* JCFrameMake.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JCFrameMake.h; sourceTree = ""; }; 282FD7E01E895B6400E17BFB /* JCFrameMake.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JCFrameMake.m; sourceTree = ""; }; @@ -63,15 +38,22 @@ 282FD7E41E895B6400E17BFB /* UIView+JCFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+JCFrame.m"; sourceTree = ""; }; 282FD7E51E895B6400E17BFB /* UIView+JCFrameLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+JCFrameLayout.h"; sourceTree = ""; }; 282FD7E61E895B6400E17BFB /* UIView+JCFrameLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+JCFrameLayout.m"; sourceTree = ""; }; - 282FD7EB1E895B6D00E17BFB /* SecondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = ""; }; - 282FD7EC1E895B6D00E17BFB /* SecondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = ""; }; + 2836F33A1E8CE49400C9BE35 /* JCFrameAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JCFrameAttribute.h; sourceTree = ""; }; + 2836F33B1E8CE49400C9BE35 /* JCFrameAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JCFrameAttribute.m; sourceTree = ""; }; + 2836F33F1E8E3DBA00C9BE35 /* SecondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = ""; }; + 2836F3401E8E3DBA00C9BE35 /* SecondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = ""; }; + 2836F3421E8E3DE900C9BE35 /* ExampleVC1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleVC1.h; sourceTree = ""; }; + 2836F3431E8E3DE900C9BE35 /* ExampleVC1.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleVC1.m; sourceTree = ""; }; + 2836F3451E8E438200C9BE35 /* ExampleVC2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleVC2.h; sourceTree = ""; }; + 2836F3461E8E438200C9BE35 /* ExampleVC2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleVC2.m; sourceTree = ""; }; + 2865622D1E8FA0D100707580 /* DevTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DevTest.h; sourceTree = ""; }; + 2865622E1E8FA0D100707580 /* DevTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DevTest.m; sourceTree = ""; }; 28D22ADD1E8911C9002245F9 /* JCFrameLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JCFrameLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; 28D22AE11E8911C9002245F9 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 28D22AE31E8911C9002245F9 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 28D22AE41E8911C9002245F9 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 28D22AE61E8911C9002245F9 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 28D22AE71E8911C9002245F9 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; - 28D22AEA1E8911C9002245F9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 28D22AEC1E8911C9002245F9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28D22AEF1E8911C9002245F9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 28D22AF11E8911C9002245F9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -79,6 +61,13 @@ 28E5EAD31E8B84A000701A93 /* JCFrameExecutor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JCFrameExecutor.h; sourceTree = ""; }; 28E5EAD41E8B84A000701A93 /* JCFrameExecutor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JCFrameExecutor.m; sourceTree = ""; }; 28E5EAD61E8BB16700701A93 /* JCFrameUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JCFrameUtilities.h; sourceTree = ""; }; + 28F35D6C1E8E468C0028340C /* ExampleVC3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleVC3.h; sourceTree = ""; }; + 28F35D6D1E8E468C0028340C /* ExampleVC3.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleVC3.m; sourceTree = ""; }; + 28F35D6F1E8E470D0028340C /* ExampleVC4.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleVC4.h; sourceTree = ""; }; + 28F35D701E8E470D0028340C /* ExampleVC4.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleVC4.m; sourceTree = ""; }; + 28F35D721E8E4F2F0028340C /* ExampleVC5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleVC5.h; sourceTree = ""; }; + 28F35D731E8E4F2F0028340C /* ExampleVC5.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleVC5.m; sourceTree = ""; }; + 28F35D751E8E5AB80028340C /* QQ20170331-173628.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "QQ20170331-173628.png"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -92,48 +81,20 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 282FD7BC1E895B5E00E17BFB /* Masonry */ = { - isa = PBXGroup; - children = ( - 282FD7BD1E895B5E00E17BFB /* MASCompositeConstraint.h */, - 282FD7BE1E895B5E00E17BFB /* MASCompositeConstraint.m */, - 282FD7BF1E895B5E00E17BFB /* MASConstraint+Private.h */, - 282FD7C01E895B5E00E17BFB /* MASConstraint.h */, - 282FD7C11E895B5E00E17BFB /* MASConstraint.m */, - 282FD7C21E895B5E00E17BFB /* MASConstraintMaker.h */, - 282FD7C31E895B5E00E17BFB /* MASConstraintMaker.m */, - 282FD7C41E895B5E00E17BFB /* MASLayoutConstraint.h */, - 282FD7C51E895B5E00E17BFB /* MASLayoutConstraint.m */, - 282FD7C61E895B5E00E17BFB /* Masonry.h */, - 282FD7C71E895B5E00E17BFB /* MASUtilities.h */, - 282FD7C81E895B5E00E17BFB /* MASViewAttribute.h */, - 282FD7C91E895B5E00E17BFB /* MASViewAttribute.m */, - 282FD7CA1E895B5E00E17BFB /* MASViewConstraint.h */, - 282FD7CB1E895B5E00E17BFB /* MASViewConstraint.m */, - 282FD7CC1E895B5E00E17BFB /* NSArray+MASAdditions.h */, - 282FD7CD1E895B5E00E17BFB /* NSArray+MASAdditions.m */, - 282FD7CE1E895B5E00E17BFB /* NSArray+MASShorthandAdditions.h */, - 282FD7CF1E895B5E00E17BFB /* NSLayoutConstraint+MASDebugAdditions.h */, - 282FD7D01E895B5E00E17BFB /* NSLayoutConstraint+MASDebugAdditions.m */, - 282FD7D11E895B5E00E17BFB /* View+MASAdditions.h */, - 282FD7D21E895B5E00E17BFB /* View+MASAdditions.m */, - 282FD7D31E895B5E00E17BFB /* View+MASShorthandAdditions.h */, - ); - path = Masonry; - sourceTree = ""; - }; 282FD7DD1E895B6400E17BFB /* JCFrameLayout */ = { isa = PBXGroup; children = ( 282FD7DE1E895B6400E17BFB /* JCFrameLayout.h */, 28E5EA981E8A42F300701A93 /* JCFrameLayoutConst.h */, + 28E5EAD61E8BB16700701A93 /* JCFrameUtilities.h */, 282FD7DF1E895B6400E17BFB /* JCFrameMake.h */, 282FD7E01E895B6400E17BFB /* JCFrameMake.m */, 282FD7E11E895B6400E17BFB /* JCFrame.h */, 282FD7E21E895B6400E17BFB /* JCFrame.m */, + 2836F33A1E8CE49400C9BE35 /* JCFrameAttribute.h */, + 2836F33B1E8CE49400C9BE35 /* JCFrameAttribute.m */, 28E5EAD31E8B84A000701A93 /* JCFrameExecutor.h */, 28E5EAD41E8B84A000701A93 /* JCFrameExecutor.m */, - 28E5EAD61E8BB16700701A93 /* JCFrameUtilities.h */, 282FD7E31E895B6400E17BFB /* UIView+JCFrame.h */, 282FD7E41E895B6400E17BFB /* UIView+JCFrame.m */, 282FD7E51E895B6400E17BFB /* UIView+JCFrameLayout.h */, @@ -142,6 +103,27 @@ path = JCFrameLayout; sourceTree = ""; }; + 2836F33E1E8E3DBA00C9BE35 /* Examples */ = { + isa = PBXGroup; + children = ( + 2836F33F1E8E3DBA00C9BE35 /* SecondViewController.h */, + 2836F3401E8E3DBA00C9BE35 /* SecondViewController.m */, + 2836F3421E8E3DE900C9BE35 /* ExampleVC1.h */, + 2836F3431E8E3DE900C9BE35 /* ExampleVC1.m */, + 2836F3451E8E438200C9BE35 /* ExampleVC2.h */, + 2836F3461E8E438200C9BE35 /* ExampleVC2.m */, + 28F35D6C1E8E468C0028340C /* ExampleVC3.h */, + 28F35D6D1E8E468C0028340C /* ExampleVC3.m */, + 28F35D6F1E8E470D0028340C /* ExampleVC4.h */, + 28F35D701E8E470D0028340C /* ExampleVC4.m */, + 28F35D721E8E4F2F0028340C /* ExampleVC5.h */, + 28F35D731E8E4F2F0028340C /* ExampleVC5.m */, + 2865622D1E8FA0D100707580 /* DevTest.h */, + 2865622E1E8FA0D100707580 /* DevTest.m */, + ); + path = Examples; + sourceTree = ""; + }; 28D22AD41E8911C9002245F9 = { isa = PBXGroup; children = ( @@ -162,17 +144,15 @@ isa = PBXGroup; children = ( 282FD7DD1E895B6400E17BFB /* JCFrameLayout */, + 2836F33E1E8E3DBA00C9BE35 /* Examples */, 28D22AE31E8911C9002245F9 /* AppDelegate.h */, 28D22AE41E8911C9002245F9 /* AppDelegate.m */, 28D22AE61E8911C9002245F9 /* ViewController.h */, 28D22AE71E8911C9002245F9 /* ViewController.m */, - 282FD7EB1E895B6D00E17BFB /* SecondViewController.h */, - 282FD7EC1E895B6D00E17BFB /* SecondViewController.m */, - 28D22AE91E8911C9002245F9 /* Main.storyboard */, 28D22AEC1E8911C9002245F9 /* Assets.xcassets */, 28D22AEE1E8911C9002245F9 /* LaunchScreen.storyboard */, 28D22AF11E8911C9002245F9 /* Info.plist */, - 282FD7BC1E895B5E00E17BFB /* Masonry */, + 28F35D751E8E5AB80028340C /* QQ20170331-173628.png */, 28D22AE01E8911C9002245F9 /* Supporting Files */, ); path = JCFrameLayout; @@ -247,7 +227,7 @@ files = ( 28D22AF01E8911C9002245F9 /* LaunchScreen.storyboard in Resources */, 28D22AED1E8911C9002245F9 /* Assets.xcassets in Resources */, - 28D22AEB1E8911C9002245F9 /* Main.storyboard in Resources */, + 28F35D761E8E5AB80028340C /* QQ20170331-173628.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -258,38 +238,28 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 282FD7DB1E895B5E00E17BFB /* NSLayoutConstraint+MASDebugAdditions.m in Sources */, - 282FD7D91E895B5E00E17BFB /* MASViewConstraint.m in Sources */, - 282FD7D41E895B5E00E17BFB /* MASCompositeConstraint.m in Sources */, - 282FD7DA1E895B5E00E17BFB /* NSArray+MASAdditions.m in Sources */, + 2836F3441E8E3DE900C9BE35 /* ExampleVC1.m in Sources */, 28D22AE81E8911C9002245F9 /* ViewController.m in Sources */, + 2865622F1E8FA0D100707580 /* DevTest.m in Sources */, + 2836F3471E8E438200C9BE35 /* ExampleVC2.m in Sources */, 28D22AE51E8911C9002245F9 /* AppDelegate.m in Sources */, - 282FD7D71E895B5E00E17BFB /* MASLayoutConstraint.m in Sources */, + 28F35D711E8E470D0028340C /* ExampleVC4.m in Sources */, + 2836F33C1E8CE49400C9BE35 /* JCFrameAttribute.m in Sources */, 28D22AE21E8911C9002245F9 /* main.m in Sources */, 282FD7E91E895B6400E17BFB /* UIView+JCFrame.m in Sources */, + 28F35D741E8E4F2F0028340C /* ExampleVC5.m in Sources */, 282FD7E71E895B6400E17BFB /* JCFrameMake.m in Sources */, - 282FD7DC1E895B5E00E17BFB /* View+MASAdditions.m in Sources */, - 282FD7ED1E895B6D00E17BFB /* SecondViewController.m in Sources */, 282FD7EA1E895B6400E17BFB /* UIView+JCFrameLayout.m in Sources */, 282FD7E81E895B6400E17BFB /* JCFrame.m in Sources */, + 28F35D6E1E8E468C0028340C /* ExampleVC3.m in Sources */, 28E5EAD51E8B84A000701A93 /* JCFrameExecutor.m in Sources */, - 282FD7D81E895B5E00E17BFB /* MASViewAttribute.m in Sources */, - 282FD7D51E895B5E00E17BFB /* MASConstraint.m in Sources */, - 282FD7D61E895B5E00E17BFB /* MASConstraintMaker.m in Sources */, + 2836F3411E8E3DBA00C9BE35 /* SecondViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - 28D22AE91E8911C9002245F9 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 28D22AEA1E8911C9002245F9 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; 28D22AEE1E8911C9002245F9 /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( diff --git a/JCFrameLayout.xcodeproj/project.xcworkspace/xcuserdata/abc.xcuserdatad/UserInterfaceState.xcuserstate b/JCFrameLayout.xcodeproj/project.xcworkspace/xcuserdata/abc.xcuserdatad/UserInterfaceState.xcuserstate index b198a32..2db6ed0 100644 Binary files a/JCFrameLayout.xcodeproj/project.xcworkspace/xcuserdata/abc.xcuserdatad/UserInterfaceState.xcuserstate and b/JCFrameLayout.xcodeproj/project.xcworkspace/xcuserdata/abc.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/JCFrameLayout.xcodeproj/xcuserdata/abc.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/JCFrameLayout.xcodeproj/xcuserdata/abc.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index fe2b454..83572fc 100644 --- a/JCFrameLayout.xcodeproj/xcuserdata/abc.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/JCFrameLayout.xcodeproj/xcuserdata/abc.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -2,4 +2,48 @@ + + + + + + + + + + + + + + diff --git a/JCFrameLayout/AppDelegate.m b/JCFrameLayout/AppDelegate.m index 18e79f4..d139dc2 100644 --- a/JCFrameLayout/AppDelegate.m +++ b/JCFrameLayout/AppDelegate.m @@ -7,6 +7,7 @@ // #import "AppDelegate.h" +#import "ViewController.h" @interface AppDelegate () @@ -16,7 +17,15 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Override point for customization after application launch. + + self.window = [[UIWindow alloc]init]; + + UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:[[ViewController alloc]init]]; + + self.window.rootViewController = nav; + + [self.window makeKeyAndVisible]; + return YES; } diff --git a/JCFrameLayout/Base.lproj/Main.storyboard b/JCFrameLayout/Base.lproj/Main.storyboard deleted file mode 100644 index 4529698..0000000 --- a/JCFrameLayout/Base.lproj/Main.storyboard +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/JCFrameLayout/Examples/DevTest.h b/JCFrameLayout/Examples/DevTest.h new file mode 100644 index 0000000..2e2a735 --- /dev/null +++ b/JCFrameLayout/Examples/DevTest.h @@ -0,0 +1,13 @@ +// +// ExampleVC6.h +// JCFrameLayout +// +// Created by abc on 17/4/1. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import + +@interface DevTest : UIViewController + +@end diff --git a/JCFrameLayout/Examples/DevTest.m b/JCFrameLayout/Examples/DevTest.m new file mode 100644 index 0000000..d55e19e --- /dev/null +++ b/JCFrameLayout/Examples/DevTest.m @@ -0,0 +1,75 @@ +// +// ExampleVC6.m +// JCFrameLayout +// +// Created by abc on 17/4/1. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import "DevTest.h" + +#import "JCFrameLayout.h" + +@interface DevTest () +/** + * <#注释#> + **/ +@property (nonatomic,strong) UIView *yellowView; +/** + * <#注释#> + **/ +@property (nonatomic,strong) UIView *redView; +@end + +@implementation DevTest + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.view.backgroundColor = [UIColor whiteColor]; + + _yellowView = [[UIView alloc]init]; + _yellowView.backgroundColor = [UIColor yellowColor]; + [self.view addSubview:_yellowView]; + + [_yellowView jc_makeLayout:^(JCFrameMake *make) { + make.width.height.jc_equalTo(200); + make.center.equalTo(self.view); + }]; + + [_yellowView addObserver:self forKeyPath:@"frame" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil]; + + _redView = [[UIView alloc]init]; + _redView.backgroundColor = [UIColor redColor]; + [self.view addSubview:_redView]; + + [_redView jc_makeLayout:^(JCFrameMake *make) { + make.center.equalTo(_yellowView); + make.size.jc_equalTo(CGSizeMake(100, 100)); + }]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ + if (object == self.yellowView && [keyPath isEqualToString: @"frame"]) { + NSLog(@"--change = %@",change); + }else{ + NSLog(@"--non--change = %@",change); + } +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ +// [UIView animateWithDuration:1 animations:^{ +// [_yellowView jc_makeLayout:^(JCFrameMake *make) { +// make.width.height.jc_equalTo(200); +// make.center.equalTo(self.view).jc_offset(CGPointMake(0, 50)); +// }]; +// [_redView jc_updateLayout]; +// }]; +// _yellowView.jc_x_value = 110; +// _yellowView.jc_y_value = 110; +// _yellowView.jc_width_value = 200; +// _yellowView.jc_height_value = 200; +// _yellowView.center = CGPointMake(100, 100); +} + +@end diff --git a/JCFrameLayout/Examples/ExampleVC1.h b/JCFrameLayout/Examples/ExampleVC1.h new file mode 100644 index 0000000..5c41496 --- /dev/null +++ b/JCFrameLayout/Examples/ExampleVC1.h @@ -0,0 +1,13 @@ +// +// ExampleVC1.h +// JCFrameLayout +// +// Created by abc on 17/3/31. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import + +@interface ExampleVC1 : UIViewController + +@end diff --git a/JCFrameLayout/Examples/ExampleVC1.m b/JCFrameLayout/Examples/ExampleVC1.m new file mode 100644 index 0000000..a9d2d3e --- /dev/null +++ b/JCFrameLayout/Examples/ExampleVC1.m @@ -0,0 +1,88 @@ +// +// ExampleVC1.m +// JCFrameLayout +// +// Created by abc on 17/3/31. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import "ExampleVC1.h" + +#import "JCFrameLayout.h" + + +#define radomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1] + +@interface ExampleVC1 () + +@end + +@implementation ExampleVC1 + +- (void)viewDidLoad { + [super viewDidLoad]; + +self.view.backgroundColor = [UIColor whiteColor]; + + UIView *leftView = [[UIView alloc]init]; + leftView.backgroundColor = radomColor; + [self.view addSubview:leftView]; + leftView.jc_debug_key = @"leftView"; + [leftView jc_makeLayout:^(JCFrameMake *make) { + make.width.jc_equalTo(50); + make.top.jc_equalTo(50 + 64); + make.bottom.jc_equalTo(-50); + make.left.jc_equalTo(0); + }]; + + + UIView *rightView = [[UIView alloc]init]; + rightView.backgroundColor = radomColor; + [self.view addSubview:rightView]; + rightView.jc_debug_key = @"rightView"; + [rightView jc_makeLayout:^(JCFrameMake *make) { + make.width.jc_equalTo(50); + make.top.jc_equalTo(50 + 64); + make.bottom.jc_equalTo(-50); + make.right.jc_equalTo(0); + }]; + + UIView *topView = [[UIView alloc]init]; + topView.backgroundColor = radomColor; + [self.view addSubview:topView]; + topView.jc_debug_key = @"topView"; + [topView jc_makeLayout:^(JCFrameMake *make) { + make.top.jc_equalTo(64); + make.height.jc_equalTo(50); + make.left.jc_equalTo(50); + make.right.jc_equalTo(-50); + }]; + + UIView *bottomView = [[UIView alloc]init]; + bottomView.backgroundColor = radomColor; + [self.view addSubview:bottomView]; + bottomView.jc_debug_key = @"bottomView"; + [bottomView jc_makeLayout:^(JCFrameMake *make) { + make.height.jc_equalTo(50); + make.left.jc_equalTo(50); + make.right.jc_equalTo(-50); + make.bottom.jc_equalTo(0); + }]; + + + UIView *centerView = [[UIView alloc]init]; + centerView.backgroundColor = radomColor; + [self.view addSubview:centerView]; + centerView.jc_debug_key = @"centerView"; + [centerView jc_makeLayout:^(JCFrameMake *make) { + make.left.equalTo(leftView.jc_right); + make.top.equalTo(topView.jc_bottom); + make.right.equalTo(rightView.jc_left); + make.bottom.equalTo(bottomView.jc_top); + }]; + NSLog(@"centerView.frame = %@",[NSValue valueWithCGRect:centerView.frame]); + [self.view sendSubviewToBack:centerView]; + +} + +@end diff --git a/JCFrameLayout/Examples/ExampleVC2.h b/JCFrameLayout/Examples/ExampleVC2.h new file mode 100644 index 0000000..bf2125b --- /dev/null +++ b/JCFrameLayout/Examples/ExampleVC2.h @@ -0,0 +1,13 @@ +// +// ExampleVC2.h +// JCFrameLayout +// +// Created by abc on 17/3/31. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import + +@interface ExampleVC2 : UIViewController + +@end diff --git a/JCFrameLayout/Examples/ExampleVC2.m b/JCFrameLayout/Examples/ExampleVC2.m new file mode 100644 index 0000000..fcb5fc2 --- /dev/null +++ b/JCFrameLayout/Examples/ExampleVC2.m @@ -0,0 +1,60 @@ +// +// ExampleVC2.m +// JCFrameLayout +// +// Created by abc on 17/3/31. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import "ExampleVC2.h" + +#import "JCFrameLayout.h" + +#define radomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1] + + +@interface ExampleVC2 () + +@end + +@implementation ExampleVC2 + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.view.backgroundColor = [UIColor whiteColor]; + + //列数 + int column = 3; + //内间距 + CGFloat padding = 20; + //每个方块尺寸 + CGFloat width = (JC_SCREEN_WIDTH - padding * (column + 1))/column; + CGFloat height = width; + + for (int i = 0; i< 9; i++) { + + //计算X左边 + int col = i % column; + CGFloat x = col * (width + padding) + padding; + + //计算Y左边 + int row = i / column; + CGFloat y = row * (height + padding) + padding + 64; + + UIView *view = [[UIView alloc]init]; + [self.view addSubview:view]; + view.backgroundColor = radomColor; + + //使用JCFrameLayout进行布局 + [view jc_makeLayout:^(JCFrameMake *make) { + make.width.jc_equalTo(width); + make.height.jc_equalTo(height); + make.left.jc_equalTo(x); + make.top.jc_equalTo(y); + }]; + } + +} + +@end diff --git a/JCFrameLayout/Examples/ExampleVC3.h b/JCFrameLayout/Examples/ExampleVC3.h new file mode 100644 index 0000000..12efe93 --- /dev/null +++ b/JCFrameLayout/Examples/ExampleVC3.h @@ -0,0 +1,13 @@ +// +// ExampleVC3.h +// JCFrameLayout +// +// Created by abc on 17/3/31. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import + +@interface ExampleVC3 : UIViewController + +@end diff --git a/JCFrameLayout/Examples/ExampleVC3.m b/JCFrameLayout/Examples/ExampleVC3.m new file mode 100644 index 0000000..6ff9e27 --- /dev/null +++ b/JCFrameLayout/Examples/ExampleVC3.m @@ -0,0 +1,77 @@ +// +// ExampleVC3.m +// JCFrameLayout +// +// Created by abc on 17/3/31. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import "ExampleVC3.h" + +#import "JCFrameLayout.h" + +#define radomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1] + +@interface ExampleVC3 () + +@end + +@implementation ExampleVC3 + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.view.backgroundColor = [UIColor whiteColor]; + + //列数 + int column = 3; + //内间距 + CGFloat padding = 20; + //每个方块尺寸 + CGFloat width = (JC_SCREEN_WIDTH - padding * (column + 1))/column; + CGFloat height = width; + + for (int idx = 0; idx < 9; idx++) { + + //计算所处行数 + int row = idx / column; + //计算所处列数 + int col = idx % column; + + UIView *view = [[UIView alloc]init]; + view.jc_debug_key = [NSString stringWithFormat:@"view_%zd",idx]; + view.backgroundColor = radomColor; + + if (row == 0 && col == 0) { + //如果是第一行第一个列,则相对屏幕左上角进行布局 + [view jc_makeLayout:^(JCFrameMake *make) { + make.left.jc_equalTo(padding); + make.top.jc_equalTo(padding + 64); + make.width.jc_equalTo(width); + make.height.jc_equalTo(height); + }]; + }else{ + //其他方块相对于前一个方块进行布局 + //取出前一个方块 + UIView *lastView = [self.view.subviews lastObject]; + + if (col == 0) { //和前一个方块在同一行 + [view jc_makeLayout:^(JCFrameMake *make) { + make.top.equalTo(lastView.jc_bottom).jc_offset(padding); + make.left.jc_equalTo(padding); + make.width.jc_equalTo(width); + make.height.jc_equalTo(height); + }]; + }else{ //和前一个方块不再同一行 + [view jc_makeLayout:^(JCFrameMake *make) { + make.left.equalTo(lastView.jc_right).jc_offset(padding); + make.top.equalTo(lastView); + make.width.jc_equalTo(width); + make.height.jc_equalTo(height); + }]; + } + } + [self.view addSubview:view]; + } +} +@end diff --git a/JCFrameLayout/Examples/ExampleVC4.h b/JCFrameLayout/Examples/ExampleVC4.h new file mode 100644 index 0000000..11dcb38 --- /dev/null +++ b/JCFrameLayout/Examples/ExampleVC4.h @@ -0,0 +1,13 @@ +// +// ExampleVC4.h +// JCFrameLayout +// +// Created by abc on 17/3/31. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import + +@interface ExampleVC4 : UIViewController + +@end diff --git a/JCFrameLayout/Examples/ExampleVC4.m b/JCFrameLayout/Examples/ExampleVC4.m new file mode 100644 index 0000000..9828a1c --- /dev/null +++ b/JCFrameLayout/Examples/ExampleVC4.m @@ -0,0 +1,54 @@ +// +// ExampleVC4.m +// JCFrameLayout +// +// Created by abc on 17/3/31. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import "ExampleVC4.h" + +#import "JCFrameLayout.h" + +#define radomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1] + + +@interface ExampleVC4 () + +@end + +@implementation ExampleVC4 + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.view.backgroundColor = [UIColor whiteColor]; + + int column = 50; + + CGFloat padding = 2; + + CGFloat width = ([UIScreen mainScreen].bounds.size.width - padding * (column + 1))/column; + CGFloat height = width; + + for (int i = 0; i<5000; i++) { + int row = i / column; + int col = i % column; + + CGFloat x = col * (width + padding) + padding; + CGFloat y = row * (height + padding) + padding + 64; + + UIView *view = [[UIView alloc]init]; + [self.view addSubview:view]; + view.backgroundColor = radomColor; + [view jc_makeLayout:^(JCFrameMake *make) { + make.width.jc_equalTo(width); + make.height.jc_equalTo(height); + make.left.jc_equalTo(x); + make.top.jc_equalTo(y); + }]; + } +} + + +@end diff --git a/JCFrameLayout/Examples/ExampleVC5.h b/JCFrameLayout/Examples/ExampleVC5.h new file mode 100644 index 0000000..7f4ec59 --- /dev/null +++ b/JCFrameLayout/Examples/ExampleVC5.h @@ -0,0 +1,13 @@ +// +// ExampleVC5.h +// JCFrameLayout +// +// Created by abc on 17/3/31. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import + +@interface ExampleVC5 : UIViewController + +@end diff --git a/JCFrameLayout/Examples/ExampleVC5.m b/JCFrameLayout/Examples/ExampleVC5.m new file mode 100644 index 0000000..240074b --- /dev/null +++ b/JCFrameLayout/Examples/ExampleVC5.m @@ -0,0 +1,76 @@ +// +// ExampleVC5.m +// JCFrameLayout +// +// Created by abc on 17/3/31. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import "ExampleVC5.h" + +#import "JCFrameLayout.h" + +#define radomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1] + + +@interface ExampleVC5 () + +@end + +@implementation ExampleVC5 + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.view.backgroundColor = [UIColor whiteColor]; + + int column = 50; + int count = 5000; + + CGFloat padding = 2; + + CGFloat width = ([UIScreen mainScreen].bounds.size.width - padding * (column + 1))/column; + CGFloat height = width; + + for (int idx = 0; idx + **/ +@property (nonatomic,strong) UIView *redView; + +/** + * <#注释#> + **/ +@property (nonatomic,strong) UIView *greenView; +@end + +@implementation SecondViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.view.backgroundColor = [UIColor whiteColor]; + + self.redView = [[UIView alloc]init]; + self.redView.backgroundColor = [UIColor redColor]; + [self.view addSubview:self.redView]; + + self.greenView = [[UIView alloc]init]; + self.greenView.backgroundColor = [UIColor greenColor]; + [self.view addSubview:self.greenView]; + + self.redView.jc_debug_key = @"redView"; + [self.redView jc_makeLayout:^(JCFrameMake *make) { + make.center.jc_equalTo(CGPointMake(100, 100)); + make.size.jc_equalTo(CGSizeMake(100, 100)); + }]; + + self.greenView.jc_debug_key = @"greenView"; + [self.greenView jc_makeLayout:^(JCFrameMake *make) { + +// 25. left and right and top and bottom +// make.left.top.jc_equalTo(20); +// make.right.bottom.jc_equalTo(-20); + make.left.top.equalTo(self.redView).jc_offset(-10); + make.right.bottom.equalTo(self.redView).jc_offset(10); + +// 24. right and top and bottom and width +// make.right.equalTo(self.redView); +// make.right.jc_equalTo(-50); +//// make.top.equalTo(self.redView.jc_centerY); +// make.top.jc_equalTo(20); +// make.bottom.equalTo(self.redView); +//// make.bottom.jc_equalTo(-50); +// make.width.equalTo(self.redView); + +// 23. left and top and bottom and width +// make.left.equalTo(self.redView.jc_right); +//// make.top.equalTo(self.redView.jc_centerY); +// make.top.jc_equalTo(20); +// make.bottom.equalTo(self.redView); +//// make.bottom.jc_equalTo(-50); +// make.width.equalTo(self.redView); + +// 22. left and right and bottom and height +// make.left.equalTo(self.redView); +// make.right.equalTo(self.redView.jc_centerX); +// make.bottom.equalTo(self.redView.jc_top); +// make.height.equalTo(self.redView); + +// 21. left and right and top and height +// make.left.equalTo(self.redView.jc_centerX); +// make.right.equalTo(self.redView); +// make.top.equalTo(self.redView.jc_bottom); +// make.height.equalTo(self.redView); + +// 20. right and bottom and width and height +// make.right.equalTo(self.redView.jc_centerX); +// make.bottom.equalTo(self.redView.jc_centerY); +// make.width.height.equalTo(self.redView); + +// 19. right and top and width and height +// make.right.equalTo(self.redView.jc_centerX); +// make.top.equalTo(self.redView.jc_bottom); +// make.width.height.equalTo(self.redView); + +// 18. left and bottom and width and height +// make.left.equalTo(self.redView.jc_right); +// make.bottom.equalTo(self.redView.jc_centerY); +// make.width.height.equalTo(self.redView); + +// 17. left and top and width and height +// make.left.equalTo(self.redView.jc_right); +// make.top.equalTo(self.redView.jc_bottom); +// make.width.height.equalTo(self.redView); + +// 16. centerY and right and width and height +// make.centerY.equalTo(self.redView.jc_bottom); +// make.right.equalTo(self.redView.jc_centerX); +// make.width.equalTo(self.redView); +// make.height.equalTo(self.redView); + +// 15. centerY and left and width and height +// make.centerY.equalTo(self.redView.jc_bottom); +// make.left.equalTo(self.redView.jc_right); +// make.width.equalTo(self.redView); +// make.height.equalTo(self.redView); + +// 14. centerX and bottom and width and height +// make.centerX.equalTo(self.redView.jc_bottom); +// make.bottom.equalTo(self.redView.jc_centerY); +// make.width.equalTo(self.redView); +// make.height.equalTo(self.redView); + +// 13. centerX and top and width and height +// make.centerX.equalTo(self.redView.jc_right); +// make.top.equalTo(self.redView.jc_bottom); +// make.width.equalTo(self.redView); +// make.height.equalTo(self.redView); + +// 12. centerX and centerY and width and height +// make.centerX.equalTo(self.redView.jc_left); +// make.centerY.equalTo(self.redView.jc_top); +// make.width.equalTo(self.redView).multipliedBy(1.5); +// make.height.equalTo(self.redView).multipliedBy(2); + +// 11. right and bottom and size +// make.right.equalTo(self.redView.jc_left); +// make.bottom.equalTo(self.redView.jc_top); +// make.size.equalTo(self.redView).multipliedBy(2); + +// 10. right and top and size +// make.right.equalTo(self.redView.jc_left); +// make.top.equalTo(self.redView.jc_bottom); +// make.size.equalTo(self.redView).multipliedBy(2); + +// 9. left and bottom and size +// make.left.equalTo(self.redView.jc_right); +// make.bottom.equalTo(self.redView.jc_top); +// make.size.equalTo(self.redView).multipliedBy(2); + +// 8. left and top and size +// make.left.equalTo(self.redView.jc_right); +// make.top.equalTo(self.redView.jc_bottom); +// make.size.equalTo(self.redView).multipliedBy(2); + +// 7. centerY and right and size +// make.centerY.equalTo(self.redView.jc_bottom); +// make.right.equalTo(self.redView.jc_left); +// make.size.equalTo(self.redView); + +// 6. centerY and left and size +// make.centerY.equalTo(self.redView.jc_top); +// make.left.equalTo(self.redView.jc_right); +// make.size.equalTo(self.redView).multipliedBy(2); + +// 5. centerX and bottom and size +// make.centerX.equalTo(self.redView); +// make.bottom.equalTo(self.redView); +// make.size.equalTo(self.redView).multipliedBy(1.5).jc_offset(CGSizeMake(10, 10)); + +// 4. centerX and top and size +// make.centerX.equalTo(self.redView.jc_right); +// make.top.equalTo(self.redView.jc_centerY); +// make.size.equalTo(self.redView).multipliedBy(2).jc_offset(CGSizeMake(10, 10)); + +// 3. centerX and centerY and size +// make.centerX.equalTo(self.redView.jc_right); +// make.centerY.equalTo(self.redView.jc_bottom); +// make.size.equalTo(self.redView).multipliedBy(2).jc_offset(CGSizeMake(10, 10)); + +// 2. center and width and height +// make.width.height.equalTo(self.redView).multipliedBy(2).jc_offset(10); +// make.center.equalTo(self.redView); + +// 1. center and size +// make.center.equalTo(self.redView).multipliedBy(2).jc_offset(CGPointMake(10, 10)); +// make.size.equalTo(self.redView).multipliedBy(2).jc_offset(CGSizeMake(10, 10)); + }]; + + [self.view bringSubviewToFront:self.redView]; + + NSLog(@"self.redView.frame = %@",[NSValue valueWithCGRect:self.redView.frame]); + NSLog(@"self.greenView.frame = %@",[NSValue valueWithCGRect:self.greenView.frame]); +} + +-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ + [self dismissViewControllerAnimated:YES completion:nil]; +} + +@end diff --git a/JCFrameLayout/Info.plist b/JCFrameLayout/Info.plist index d052473..c12df3b 100644 --- a/JCFrameLayout/Info.plist +++ b/JCFrameLayout/Info.plist @@ -22,8 +22,6 @@ UILaunchStoryboardName LaunchScreen - UIMainStoryboardFile - Main UIRequiredDeviceCapabilities armv7 diff --git a/JCFrameLayout/JCFrameLayout/JCFrame.h b/JCFrameLayout/JCFrameLayout/JCFrame.h index dea8c2a..100e692 100644 --- a/JCFrameLayout/JCFrameLayout/JCFrame.h +++ b/JCFrameLayout/JCFrameLayout/JCFrame.h @@ -9,6 +9,7 @@ #import #import "JCFrameLayoutConst.h" #import "JCFrameUtilities.h" +#import "JCFrameAttribute.h" @class JCFrame; @@ -22,21 +23,35 @@ @property (nonatomic,weak) id delegate; -/** - * 布局类型 - **/ -@property (nonatomic,assign,readonly) JCFrameType frameType; /** * 当前属性的值 **/ @property (nonatomic,strong,readonly) id value; +/** + * 当前属性的偏移值,只在相对布局的时候生效 + **/ +@property (nonatomic,strong,readonly) id offset; +/** + * 当前属性的倍数,只在相对布局的时候生效 + **/ +@property (nonatomic,assign,readonly) CGFloat multiplier; /** - * 布局的对象UIView + * 是否生效,便于调试,没其他用处 **/ -@property (nonatomic,weak,readonly) UIView *view; +@property (nonatomic,assign) BOOL actived; +/** + * 是否有相对属性 + **/ +@property (nonatomic,assign,readonly) BOOL hasRelateAttr; + +/** + * 布局属性 + **/ +@property (nonatomic,strong,strong) JCFrameAttribute *frameAttr; + -- (instancetype)initWithView:(UIView*)view frameType:(JCFrameType)frameType; +- (instancetype)initWithFrameAttribute:(JCFrameAttribute*)frameAttribute; - (JCFrame*)left; @@ -51,8 +66,11 @@ - (JCFrame*)size; #define jc_equalTo(...) equalTo(JCBoxValue((__VA_ARGS__))) +#define jc_offset(...) jc_offset(JCBoxValue((__VA_ARGS__))) - (JCFrame*(^)(id))jc_equalTo; - (JCFrame*(^)(id))equalTo; +- (JCFrame*(^)(CGFloat))multipliedBy; +- (JCFrame*(^)(id))jc_offset; @end diff --git a/JCFrameLayout/JCFrameLayout/JCFrame.m b/JCFrameLayout/JCFrameLayout/JCFrame.m index 1d0bf85..1d55c14 100644 --- a/JCFrameLayout/JCFrameLayout/JCFrame.m +++ b/JCFrameLayout/JCFrameLayout/JCFrame.m @@ -13,39 +13,98 @@ @interface JCFrame () /** - * <#注释#> + * 链表前驱 + * e.g. + * make.left.top.jc_equal(100); + * 当前对象为top时,chainPreviousFrame为left **/ -@property (nonatomic,weak) JCFrame *chainParentFrame; +@property (nonatomic,weak) JCFrame *chainPreviousFrame; + +/** + * 给UIView设置一个key值,用于方便调试 + * UIView+JCFrame中已经定义了一个,这里的冗余是因为在delloc中获取不到UIView.jc_debug_key,UIView已经被释放 + **/ +@property (nonatomic,copy) NSString *jc_debug_key; @end @implementation JCFrame -- (instancetype)initWithView:(UIView*)view frameType:(JCFrameType)frameType{ +- (instancetype)initWithFrameAttribute:(JCFrameAttribute*)frameAttribute{ self = [super init]; if (self) { - self->_frameType = frameType; - self->_view = view; - [self.view.jc_frames addObject:self]; + self->_frameAttr = frameAttribute; + self->_multiplier = 1; + self.jc_debug_key = frameAttribute.currentView.jc_debug_key; } return self; } - (JCFrame*(^)(id))equalTo{ return ^id(id value){ - self->_value = value; + + //NSValue(CGFloat\CGSize\CGPoint) + //UIView + //JCFrame + + /* + make.left.equal(redView); + + */ + if([value isKindOfClass:NSNumber.class] //CGFloat + || [value isKindOfClass:NSValue.class]) { //CGSize,CGPoint + + self->_value = value; + + }else if([value isKindOfClass:UIView.class]){ + self->_hasRelateAttr = YES; + //如果传入UIView,则相对布局属性采用与本类相同的属性 + self.frameAttr.relateView = (UIView*)value; + self.frameAttr.relateFrameType = self.frameAttr.currentFrameType; + + }else if([value isKindOfClass:JCFrameAttribute.class]){ + self->_hasRelateAttr = YES; + //如果传入JCFrame,则相对布局属性采用与本类相同的属性 + self.frameAttr.relateView = ((JCFrameAttribute*)value).currentView; + self.frameAttr.relateFrameType = ((JCFrameAttribute*)value).currentFrameType; + + } + JCFrame *currentFrame = self; - while (currentFrame.chainParentFrame) { - currentFrame.chainParentFrame->_value = value; - currentFrame = currentFrame.chainParentFrame; + while (currentFrame.chainPreviousFrame) { + currentFrame = currentFrame.chainPreviousFrame; + currentFrame.equalTo(value); } return self; }; } - - (JCFrame*(^)(id))jc_equalTo{ return self.equalTo; } +- (JCFrame*(^)(id))jc_offset{ + return ^id(id value){ + self->_offset = value; + + JCFrame *currentFrame = self; + while (currentFrame.chainPreviousFrame) { + currentFrame = currentFrame.chainPreviousFrame; + currentFrame->_offset=value; + } + return self; + }; +} +- (JCFrame*(^)(CGFloat))multipliedBy{ + return ^id(CGFloat value){ + self->_multiplier = value; + + JCFrame *currentFrame = self; + while (currentFrame.chainPreviousFrame) { + currentFrame = currentFrame.chainPreviousFrame; + currentFrame->_multiplier = value; + } + return self; + }; +} #pragma mark - support chainable syntax - (JCFrame *)left{ @@ -79,43 +138,25 @@ - (JCFrame*)size{ return [self createJCLayoutFrame:JCFrameTypeSize]; } +#pragma mark - private Method +/** + 通过代理(即JCFrameMake)创建JCFrame对象 + */ - (JCFrame *)createJCLayoutFrame:(JCFrameType)frameType{ if (self.delegate && [self.delegate respondsToSelector:@selector(jcFrame:createFrameWithframeType:)]) { JCFrame *frame = [self.delegate jcFrame:self createFrameWithframeType:frameType]; - - frame.chainParentFrame = self; - + //把self设为链表前驱 + frame.chainPreviousFrame = self; return frame; } return nil; } - (NSString *)description{ - - return [NSString stringWithFormat:@"[JCFrame: %p type=%@]",self,self. typeString]; - + return [NSString stringWithFormat:@"[JCFrame: %@,%@,%@,%@]",self.jc_debug_key,self.frameAttr.currentTypeString,self.value,(self.actived?@"actived":@"ignored")]; } - - (void)dealloc{ - JCLog(@"---JCFrame dealloc %@ , %@",self.typeString,self.value); -} - -- (NSString*)typeString{ - - switch (self.frameType) { - case JCFrameTypeLeft:return @"Left"; break; - case JCFrameTypeRight:return @"Right"; break; - case JCFrameTypeTop:return @"Top"; break; - case JCFrameTypeBottom:return @"Bottom"; break; - case JCFrameTypeWidth:return @"Width"; break; - case JCFrameTypeHeight:return @"Height"; break; - case JCFrameTypeCenterX:return @"CenterX"; break; - case JCFrameTypeCenterY:return @"CenterY"; break; - case JCFrameTypeCenter:return @"Center"; break; - case JCFrameTypeSize:return @"Size"; break; - - default:return @"UnKnow";break; - } + JCLog(@"---JCFrame dealloc %@,%@,%@,%@",self.jc_debug_key,self.frameAttr.currentTypeString,self.value,(self.actived?@"actived":@"ignored")); } @end diff --git a/JCFrameLayout/JCFrameLayout/JCFrameAttribute.h b/JCFrameLayout/JCFrameLayout/JCFrameAttribute.h new file mode 100644 index 0000000..4c2d79d --- /dev/null +++ b/JCFrameLayout/JCFrameLayout/JCFrameAttribute.h @@ -0,0 +1,35 @@ +// +// JCFrameAttribute.h +// JCFrameLayout +// +// Created by abc on 17/3/30. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import + +#import "JCFrameLayoutConst.h" + +@interface JCFrameAttribute : NSObject + +/** + * 当前需要布局的UIView + **/ +@property (nonatomic,weak) UIView *currentView; +/** + * 当前需要布局的属性 + **/ +@property (nonatomic,assign) JCFrameType currentFrameType; +/** + * 相对于哪个UIView进行布局 + **/ +@property (nonatomic,weak) UIView *relateView; +/** + * 相对于哪个UIView的哪个属性进行布局 + **/ +@property (nonatomic,assign) JCFrameType relateFrameType; + +- (instancetype)initWithView:(UIView*)currentView frameType:(JCFrameType)currentFrameType; + +- (NSString*)currentTypeString; +@end diff --git a/JCFrameLayout/JCFrameLayout/JCFrameAttribute.m b/JCFrameLayout/JCFrameLayout/JCFrameAttribute.m new file mode 100644 index 0000000..ace2c91 --- /dev/null +++ b/JCFrameLayout/JCFrameLayout/JCFrameAttribute.m @@ -0,0 +1,42 @@ +// +// JCFrameAttribute.m +// JCFrameLayout +// +// Created by abc on 17/3/30. +// Copyright © 2017年 jackcat. All rights reserved. +// + +#import "JCFrameAttribute.h" + +@implementation JCFrameAttribute + +- (instancetype)initWithView:(UIView*)currentView frameType:(JCFrameType)currentFrameType{ + self = [super init]; + if (self) { + self.currentView = currentView; + self.currentFrameType = currentFrameType; + } + return self; + +} + + +- (NSString*)currentTypeString{ + + switch (self.currentFrameType) { + case JCFrameTypeLeft:return @"Left"; break; + case JCFrameTypeRight:return @"Right"; break; + case JCFrameTypeTop:return @"Top"; break; + case JCFrameTypeBottom:return @"Bottom"; break; + case JCFrameTypeWidth:return @"Width"; break; + case JCFrameTypeHeight:return @"Height"; break; + case JCFrameTypeCenterX:return @"CenterX"; break; + case JCFrameTypeCenterY:return @"CenterY"; break; + case JCFrameTypeCenter:return @"Center"; break; + case JCFrameTypeSize:return @"Size"; break; + + default:return @"UnKnow";break; + } +} + +@end diff --git a/JCFrameLayout/JCFrameLayout/JCFrameExecutor.h b/JCFrameLayout/JCFrameLayout/JCFrameExecutor.h index 7167213..dc5fe3b 100644 --- a/JCFrameLayout/JCFrameLayout/JCFrameExecutor.h +++ b/JCFrameLayout/JCFrameLayout/JCFrameExecutor.h @@ -13,8 +13,6 @@ @interface JCFrameExecutor : NSObject -+ (void)executeWithView:(UIView*)view - frames:(NSArray*)frames - frameTypes:(JCFrameType)frameTypes; ++ (void)executeWithView:(UIView*)view; @end diff --git a/JCFrameLayout/JCFrameLayout/JCFrameExecutor.m b/JCFrameLayout/JCFrameLayout/JCFrameExecutor.m index 2978c5c..5074635 100644 --- a/JCFrameLayout/JCFrameLayout/JCFrameExecutor.m +++ b/JCFrameLayout/JCFrameLayout/JCFrameExecutor.m @@ -10,6 +10,435 @@ #import "UIView+JCFrame.h" + +#pragma mark - center 或 size 新值得计算 +/** + 根据relateCenter、multiplier、offset计算新的CGPoint + */ +CGPoint transToNewCenter(CGPoint relateCenter,CGFloat multiplier,id offset){ + CGFloat offsetX = [offset CGPointValue].x; + CGFloat offsetY = [offset CGPointValue].y; + CGFloat newCenterX = relateCenter.x * multiplier + offsetX; + CGFloat newCenterY = relateCenter.y * multiplier + offsetY; + return CGPointMake(newCenterX, newCenterY); +} + +/** + 根据relateCenter、multiplier、offset计算新的CGSize + */ +CGSize transToNewSize(CGSize relateSize,CGFloat multiplier,id offset){ + CGFloat offsetWidth = [offset CGSizeValue].width; + CGFloat offsetHeight = [offset CGSizeValue].height; + CGFloat newWidth = relateSize.width * multiplier + offsetWidth; + CGFloat newHeight = relateSize.height * multiplier + offsetHeight; + return CGSizeMake(newWidth, newHeight); +} + +#pragma mark - 设置布局属性 +void setLeftByLeftFrame(UIView*view,JCFrame*frame){ + if (frame.hasRelateAttr) { + //Left可以相对Left ,CenterX ,Right + CGFloat x = 0; + //如果相对的是父容器,则计算方式不同 + if (frame.frameAttr.relateView == view.superview) { + if (frame.frameAttr.relateFrameType == JCFrameTypeLeft) { + x = 0; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterX) { + x = view.superview.jc_width_value / 2; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeRight) { + x = view.superview.jc_width_value; + } + }else{ + if (frame.frameAttr.relateFrameType == JCFrameTypeLeft) { + x = frame.frameAttr.relateView.jc_x_value; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterX) { + x = frame.frameAttr.relateView.jc_centerX_value; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeRight) { + x = frame.frameAttr.relateView.jc_right_value; + } + } + + x = x * frame.multiplier + ((NSNumber*)frame.offset).doubleValue; + frame.jc_equalTo(x); + view.jc_x_value = x; + }else{ + view.jc_x_value = ((NSNumber*)frame.value).doubleValue; + } +} + +void setRightByRightFrame(UIView*view,JCFrame*frame){ + if (frame.hasRelateAttr) { + //right可以相对left,centerX,right + CGFloat x = 0; + //如果相对的是父容器,则计算方式不同 + if (frame.frameAttr.relateView == view.superview) { + if (frame.frameAttr.relateFrameType == JCFrameTypeLeft) { + x = 0; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterX) { + x = view.superview.jc_width_value / 2; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeRight) { + x = view.superview.jc_width_value; + } + }else{ + if (frame.frameAttr.relateFrameType == JCFrameTypeLeft) { + x = frame.frameAttr.relateView.jc_x_value; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterX) { + x = frame.frameAttr.relateView.jc_centerX_value; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeRight) { + x = frame.frameAttr.relateView.jc_right_value; + } + } + + x = (x - view.jc_width_value) * frame.multiplier + ((NSNumber*)frame.offset).doubleValue; + frame.jc_equalTo(x); + view.jc_x_value = x; + }else{ + view.jc_x_value = view.superview.jc_width_value/*父容器宽度*/-view.jc_width_value/*宽度*/+((NSNumber*)frame.value).doubleValue/*右边距,负数*/; + } + +} + +void setSizeBySizeFrame(UIView*view,JCFrame*frame){ + if (frame.hasRelateAttr) { + //size只能相对size + if (frame.frameAttr.relateFrameType == JCFrameTypeSize) { + CGSize newSize = transToNewSize(frame.frameAttr.relateView.jc_size_value, frame.multiplier, frame.offset); + frame.jc_equalTo(newSize); + view.jc_size_value = newSize; + } + } + else{ + view.jc_size_value = ((NSValue*)frame.value).CGSizeValue; + } +} + +void setCenterByCenterFrame(UIView*view,JCFrame*frame){ + if (frame.hasRelateAttr) { + //center的相对值只能是center + if(frame.frameAttr.relateFrameType == JCFrameTypeCenter){ + //1. 计算 + CGPoint newCenter = CGPointZero; + if (frame.frameAttr.relateView == view.superview) { //如果是相对于父容器,则需要特殊处理 + newCenter = CGPointMake(view.superview.jc_width_value / 2, view.superview.jc_height_value / 2); + }else{ + newCenter = frame.frameAttr.relateView.jc_center_value; + } + + newCenter = transToNewCenter(newCenter,frame.multiplier,frame.offset); + + //2. 将新的值回填回去,因为center的value属性赋值 + frame.jc_equalTo(newCenter); + //3. 设置新值 + view.jc_center_value = newCenter; + } + }else{ + view.jc_center_value = ((NSValue*)frame.value).CGPointValue; + } +} + +void setWidthByWidthFrame(UIView*view,JCFrame*frame){ + if (frame.hasRelateAttr) { + if(frame.frameAttr.relateFrameType == JCFrameTypeWidth){ + //view2.width * 倍数 + 偏移量 + CGFloat newWidth = frame.frameAttr.relateView.jc_width_value * frame.multiplier + ((NSNumber*)frame.offset).doubleValue; + //回填 + frame.jc_equalTo(newWidth); + //设置 + view.jc_width_value = newWidth; + } + }else{ + view.jc_width_value = ((NSNumber*)frame.value).doubleValue; + } +} + +void setHeightByHeightFrame(UIView*view,JCFrame*frame){ + if (frame.hasRelateAttr) { + //height只能相对height + if(frame.frameAttr.relateFrameType == JCFrameTypeHeight){ + //计算新值 + CGFloat newHeight = frame.frameAttr.relateView.jc_height_value * frame.multiplier + ((NSNumber*)frame.offset).doubleValue; + //回填 + frame.jc_equalTo(newHeight); + //设置 + view.jc_height_value = newHeight; + } + }else{ + view.jc_height_value = ((NSNumber*)frame.value).doubleValue; + } +} + +void setCenterXByCenterXFrame(UIView*view,JCFrame*frame){ + if (frame.hasRelateAttr) { + /** + centerX相对值可以有left,centerX,right三个 + */ + CGFloat newCenterX = 0; + + //如果相对的是父容器,则计算方式不同 + if (frame.frameAttr.relateView == view.superview) { + if (frame.frameAttr.relateFrameType == JCFrameTypeLeft) {//Left + newCenterX = 0; + + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterX) {//CenterX + newCenterX = view.superview.jc_width_value / 2; + + }else if (frame.frameAttr.relateFrameType == JCFrameTypeRight) {//Right + newCenterX = view.superview.jc_width_value; + + } + }else{ + if (frame.frameAttr.relateFrameType == JCFrameTypeLeft) {//Left + newCenterX = frame.frameAttr.relateView.jc_x_value; + + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterX) {//CenterX + newCenterX = frame.frameAttr.relateView.jc_centerX_value; + + }else if (frame.frameAttr.relateFrameType == JCFrameTypeRight) {//Right + newCenterX = frame.frameAttr.relateView.jc_right_value; + + } + } + + newCenterX = newCenterX * frame.multiplier + ((NSNumber*)frame.offset).doubleValue; + frame.jc_equalTo(newCenterX); + view.jc_centerX_value = newCenterX; + }else{ + view.jc_centerX_value = ((NSNumber*)frame.value).doubleValue; + } +} + +void setCenterYByCenterYFrame(UIView*view,JCFrame*frame){ + if (frame.hasRelateAttr) { + /** + centerY相对值可以有top,centerY,bottom三个 + */ + CGFloat newCenterY = 0; + //如果相对的是父容器,则计算方式不同 + if (frame.frameAttr.relateView == view.superview) { + if (frame.frameAttr.relateFrameType == JCFrameTypeTop) {//top + newCenterY = 0; + + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterY) {//CenterY + newCenterY = view.superview.jc_height_value / 2; + + }else if (frame.frameAttr.relateFrameType == JCFrameTypeBottom) {//bottom + newCenterY = view.superview.jc_height_value; + } + }else{ + if (frame.frameAttr.relateFrameType == JCFrameTypeTop) {//top + newCenterY = frame.frameAttr.relateView.jc_y_value; + + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterY) {//CenterY + newCenterY = frame.frameAttr.relateView.jc_centerY_value; + + }else if (frame.frameAttr.relateFrameType == JCFrameTypeBottom) {//bottom + newCenterY = frame.frameAttr.relateView.jc_bottom_value; + } + } + + + newCenterY = newCenterY * frame.multiplier + ((NSNumber*)frame.offset).doubleValue; + + frame.jc_equalTo(newCenterY); + view.jc_centerY_value = newCenterY; + }else{ + view.jc_centerY_value = ((NSNumber*)frame.value).doubleValue; + } +} + +void setTopByTopFrame(UIView*view,JCFrame*frame){ + if (frame.hasRelateAttr) { + //top 可以相对 top,centerY,bottom + CGFloat newTop = 0; + //如果相对的是父容器,则计算方式不同 + if (frame.frameAttr.relateView == view.superview) { + if (frame.frameAttr.relateFrameType == JCFrameTypeTop) { + newTop = 0; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterY) { + newTop = view.superview.jc_height_value / 2; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeBottom) { + newTop = view.superview.jc_height_value; + } + }else{ + if (frame.frameAttr.relateFrameType == JCFrameTypeTop) { + newTop = frame.frameAttr.relateView.jc_y_value; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterY) { + newTop = frame.frameAttr.relateView.jc_centerY_value; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeBottom) { + newTop = frame.frameAttr.relateView.jc_bottom_value; + } + } + + newTop = newTop * frame.multiplier + ((NSNumber*)frame.offset).doubleValue; + //回填 + frame.jc_equalTo(newTop); + //设置 + view.jc_y_value = newTop; + }else{ + view.jc_y_value = ((NSNumber*)frame.value).doubleValue; + } +} + +void setBottomByBottomFrame(UIView*view,JCFrame*frame){ + if (frame.hasRelateAttr) { + //bottom可以相对top,centerY,bottom + CGFloat y = 0; + //如果相对的是父容器,则计算方式不同 + if (frame.frameAttr.relateView == view.superview) { + if (frame.frameAttr.relateFrameType == JCFrameTypeTop) { //Top + y = 0; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterY) { //CenterY + y = view.superview.jc_height_value / 2; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeBottom) { //Bottom + y = view.superview.jc_height_value; + } + }else{ + if (frame.frameAttr.relateFrameType == JCFrameTypeTop) { //Top + y = frame.frameAttr.relateView.jc_y_value; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeCenterY) { //CenterY + y = frame.frameAttr.relateView.jc_centerY_value; + }else if (frame.frameAttr.relateFrameType == JCFrameTypeBottom) { //Bottom + y = frame.frameAttr.relateView.jc_bottom_value; + } + } + + y = (y - view.jc_height_value) * frame.multiplier + ((NSNumber*)frame.offset).doubleValue; + frame.jc_equalTo(y); + view.jc_y_value = y; + }else{ + view.jc_y_value = view.superview.jc_height_value/*父容器高度*/ - view.jc_height_value/*高度*/ + ((NSNumber*)frame.value).doubleValue/*距离父容器底边距,一般为负数*/; + } +} + + +#define SET_LEFT {\ +JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)];\ +setLeftByLeftFrame(view, left);\ +} + +#define SET_TOP {\ +JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)];\ +setTopByTopFrame(view, top);\ +} + +#define SET_RIGHT {\ +JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)];\ +setRightByRightFrame(view, right);\ +} + +#define SET_BOTTOM {\ +JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)];\ +setBottomByBottomFrame(view, bottom);\ +} + +#define SET_LEFT_RIGHT {\ +CGFloat leftX = 0;\ +CGFloat rightX = 0;\ +{\ + JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)];\ + if (left.hasRelateAttr) {\ + if (left.frameAttr.relateFrameType == JCFrameTypeLeft) {\ + leftX = left.frameAttr.relateView.jc_x_value;\ + }else if (left.frameAttr.relateFrameType == JCFrameTypeCenterX) {\ + leftX = left.frameAttr.relateView.jc_centerX_value;\ + }else if (left.frameAttr.relateFrameType == JCFrameTypeRight) {\ + leftX = left.frameAttr.relateView.jc_right_value;\ + }\ + leftX = leftX * left.multiplier + ((NSNumber*)left.offset).doubleValue;\ + }else{\ + leftX = ((NSNumber*)left.value).doubleValue;\ + }\ + left.jc_equalTo(leftX);\ + view.jc_x_value = leftX;\ +}\ +{\ + JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)];\ + if (right.hasRelateAttr) {\ + if (right.frameAttr.relateFrameType == JCFrameTypeLeft) {\ + rightX = right.frameAttr.relateView.jc_x_value;\ + }else if (right.frameAttr.relateFrameType == JCFrameTypeCenterX) {\ + rightX = right.frameAttr.relateView.jc_centerX_value;\ + }else if (right.frameAttr.relateFrameType == JCFrameTypeRight) {\ + rightX = right.frameAttr.relateView.jc_right_value;\ + }\ + rightX = rightX * right.multiplier + ((NSNumber*)right.offset).doubleValue;\ + }else{\ + rightX = view.superview.jc_width_value + ((NSNumber*)right.value).doubleValue;\ + }\ +}\ +view.jc_width_value = rightX/*右边X*/ - leftX/*左边X*/;\ +} + +#define SET_TOP_BOTTOM {\ +CGFloat topY = 0;\ +CGFloat bottomY = 0;\ +{\ + JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)];\ + if (top.hasRelateAttr) {\ + if (top.frameAttr.relateFrameType == JCFrameTypeTop) {\ + topY = top.frameAttr.relateView.jc_y_value;\ + }else if (top.frameAttr.relateFrameType == JCFrameTypeCenterY) {\ + topY = top.frameAttr.relateView.jc_centerY_value;\ + }else if (top.frameAttr.relateFrameType == JCFrameTypeBottom) {\ + topY = top.frameAttr.relateView.jc_bottom_value;\ + }\ + topY = topY * top.multiplier + ((NSNumber*)top.offset).doubleValue;\ + }else{\ + topY = ((NSNumber*)top.value).doubleValue;\ + }\ + top.jc_equalTo(topY);\ + view.jc_y_value = topY;\ +}\ +{\ + JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)];\ + if (bottom.hasRelateAttr) {\ + if (bottom.frameAttr.relateFrameType == JCFrameTypeTop) {\ + bottomY = bottom.frameAttr.relateView.jc_y_value;\ + }else if (bottom.frameAttr.relateFrameType == JCFrameTypeCenterY) {\ + bottomY = bottom.frameAttr.relateView.jc_centerY_value;\ + }else if (bottom.frameAttr.relateFrameType == JCFrameTypeBottom) {\ + bottomY = bottom.frameAttr.relateView.jc_bottom_value;\ + }\ + bottomY = bottomY * bottom.multiplier + ((NSNumber*)bottom.offset).doubleValue;\ + }else{\ + bottomY = view.superview.jc_height_value/*父容器高度*/ + ((NSNumber*)bottom.value).doubleValue/*底边距*/;\ + }\ +}\ +view.jc_height_value = bottomY - topY;\ +} + +#define SET_CENTER_X {\ +JCFrame *centerX = [self filterFrameIn:frames frameType:(JCFrameTypeCenterX)];\ +setCenterXByCenterXFrame(view, centerX);\ +} + +#define SET_CENTER_Y {\ +JCFrame *centerY = [self filterFrameIn:frames frameType:(JCFrameTypeCenterY)];\ +setCenterYByCenterYFrame(view, centerY);\ +} + +#define SET_WIDTH {\ +JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)];\ +setWidthByWidthFrame(view, width);\ +} + +#define SET_HEIGHT {\ +JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)];\ +setHeightByHeightFrame(view, height);\ +} + +#define SET_SIZE { \ +JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; \ +setSizeBySizeFrame(view, size); \ +} + +#define SET_CENTER {\ +JCFrame *center = [self filterFrameIn:frames frameType:(JCFrameTypeCenter)];\ +setCenterByCenterFrame(view,center);\ +} + + + @implementation JCFrameExecutor //### 属性优先级设定 @@ -28,19 +457,26 @@ @implementation JCFrameExecutor // 4. Top > Bottom // // ####可能的情况 +// 含有 center 和 size // 1. center and size +// +// 只有 center // 2. center and width and height +// +// 只有 size 和 (centerX 或 centerY) // 3. centerX and centerY and size // 4. centerX and top and size // 5. centerX and bottom and size // 6. centerY and left and size // 7. centerY and right and size +// +// 只有 size // 8. left and top and size // 9. left and bottom and size // 10. right and top and size // 11. right and bottom and size -// -------- +// 含有centerX 或 centerY // 12. centerX and centerY and width and height // 13. centerX and top and width and height // 14. centerX and bottom and width and height @@ -48,466 +484,911 @@ @implementation JCFrameExecutor // 16. centerY and right and width and height // 含有2条边界值,2个尺寸 -// 22. left and top and width and height -// 23. left and bottom and width and height -// 24. right and top and width and height -// 25. right and bottom and width and height +// 17. left and top and width and height +// 18. left and bottom and width and height +// 19. right and top and width and height +// 20. right and bottom and width and height // 含有3条边距值,1个尺寸值 -// 18. left and right and top and height -// 19. left and right and bottom and height -// 20. left and top and bottom and width -// 21. right and top and bottom and width +// 21. left and right and top and height +// 22. left and right and bottom and height +// 23. left and top and bottom and width +// 24. right and top and bottom and width // 含有4条边距值 -// 17. left and right and top and bottom +// 25. left and right and top and bottom -+ (void)executeWithView:(UIView*)view - frames:(NSArray*)frames - frameTypes:(JCFrameType)frameTypes{ ++ (void)executeWithView:(UIView*)view{ // 1. center and size + if ([self layoutByCenterAndSize:view]) { + return; + } + + // 2. center and width and height + if ([self layoutByCenterAndWidthAndHeight:view]) { + return; + } + + // 3. centerX and centerY and size + if ([self layoutByCenterXAndCenterYAndSize:view]) { + return; + } + + // 4. centerX and top and size + if ([self layoutByCenterXAndTopAndSize:view]) { + return; + } + + // 5. centerX and bottom and size + if ([self layoutByCenterXAndBottomAndSize:view]) { + return; + } + + // 6. centerY and left and size + if ([self layoutByCenterYAndLeftAndSize:view]) { + return; + } + + + // 7. centerY and right and size + if ([self layoutByCenterYAndRightAndSize:view]) { + return; + } + + // 8. left and top and size + if ([self layoutByLeftAndTopAndSize:view]) { + return; + } + + + // 9. left and bottom and size + if ([self layoutByLeftAndBottomAndSize:view]) { + return; + } + + // 10. right and top and size + if ([self layoutByRightAndTopAndSize:view]) { + return; + } + + + // 11. right and bottom and size + if ([self layoutByRightAndBottomAndSize:view]) { + return; + } + + // 12. centerX and centerY and width and height + if ([self layoutByCenterXAndCenterYAndWidthAndHeight:view]) { + return; + } + + // 13. centerX and top and width and height + if ([self layoutByCenterXAndTopAndWidthAndHeight:view]) { + return; + } + + // 14. centerX and bottom and width and height + if ([self layoutByCenterXAndBottomAndWidthAndHeight:view]) { + return; + } + + // 15. centerY and left and width and height + if ([self layoutByCenterYAndLeftAndWidthAndHeight:view]) { + return; + } + + // 16. centerY and right and width and height + if ([self layoutByCenterYAndRightAndWidthAndHeight:view]) { + return; + } + + // 含有2条边界值,2个尺寸 + // 17. left and top and width and height + if ([self layoutByLeftAndTopAndWidthAndHeight:view]) { + return; + } + + // 18. left and bottom and width and height + if ([self layoutByLeftAndBottomAndWidthAndHeight:view ]) { + return; + } + + // 19. right and top and width and height + if ([self layoutByRightAndTopAndWidthAndHeight:view]) { + return; + } + + // 20. right and bottom and width and height + if ([self layoutByRightAndBottomAndWidthAndHeight:view]) { + return; + } + + // 含有3条边距值,1个尺寸值 + // 21. left and right and top and height + if ([self layoutByLeftAndRightAndTopAndHeight:view]) { + return; + } + + // 22. left and right and bottom and height + if ([self layoutByLeftAndRightAndBottomAndHeight:view]) { + return; + } + + // 23. left and top and bottom and width + if ([self layoutByLeftAndTopAndBottomAndWidth:view]) { + return; + } + + // 24. right and top and bottom and width + if ([self layoutByRightAndTopAndBottomAndWidth:view]) { + + return; + } + + // 含有4条边距值 + // 25. left and right and top and bottom + if ([self layoutByLeftAndRightAndTopAndBottom:view]) { + + return; + } +} + +#pragma mark - 含有 center 和 size +// 1. center and size ++ (BOOL)layoutByCenterAndSize:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + if ((frameTypes & JCFrameTypeCenter) &&(frameTypes & JCFrameTypeSize)) { - JCFrame *center = [self filterFrameIn:frames frameType:(JCFrameTypeCenter)]; - JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; - view.jc_size_value = ((NSValue*)size.value).CGSizeValue; - view.jc_center_value = ((NSValue*)center.value).CGPointValue; - return; + NSArray*frames = view.jc_frames; + + JCLog(@"\n---%@--layoutByCenterAndSize\n",view.jc_debug_key); + + //1. 先size + SET_SIZE + + //2. 后Center + SET_CENTER + + return YES; } - // 2. center and width and height + return NO; +} + +#pragma mark - 只有 center +// 2. center and width and height ++ (BOOL)layoutByCenterAndWidthAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + if ((frameTypes & JCFrameTypeCenter) &&(frameTypes & JCFrameTypeWidth) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *center = [self filterFrameIn:frames frameType:(JCFrameTypeCenter)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; - view.jc_center_value = ((NSValue*)center.value).CGPointValue; - return; + NSArray*frames = view.jc_frames; + + JCLog(@"\n---%@--layoutByCenterAndWidthAndHeight\n",view.jc_debug_key); + + //1. 设置宽度 + SET_WIDTH + + //2. 设置高度 + SET_HEIGHT + + + //3. 设置center + SET_CENTER + + return YES; } + return NO; + +} + +#pragma mark - 只有 size 和 (centerX 或 centerY) +// 3. centerX and centerY and size ++ (BOOL)layoutByCenterXAndCenterYAndSize:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; - // 3. centerX and centerY and size if ((frameTypes & JCFrameTypeCenterX) &&(frameTypes & JCFrameTypeCenterY) &&(frameTypes & JCFrameTypeSize)) { - JCFrame *centerX = [self filterFrameIn:frames frameType:(JCFrameTypeCenterX)]; - JCFrame *centerY = [self filterFrameIn:frames frameType:(JCFrameTypeCenterY)]; - JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; - view.jc_centerX_value = ((NSNumber*)centerX.value).doubleValue; - view.jc_centerY_value = ((NSNumber*)centerY.value).doubleValue; - view.jc_size_value = ((NSValue*)size.value).CGSizeValue; - return; + + NSArray*frames = view.jc_frames; + + JCLog(@"\n---%@--layoutByCenterXAndCenterYAndSize\n",view.jc_debug_key); + + //1. 设置size + SET_SIZE + + //2. 设置centerX + SET_CENTER_X + + //3. 设置centerY + SET_CENTER_Y + + return YES; } - // 4. centerX and top and size + return NO; +} + +// 4. centerX and top and size ++ (BOOL)layoutByCenterXAndTopAndSize:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + if ((frameTypes & JCFrameTypeCenterX) &&(frameTypes & JCFrameTypeTop) &&(frameTypes & JCFrameTypeSize)) { - JCFrame *centerX = [self filterFrameIn:frames frameType:(JCFrameTypeCenterX)]; - JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)]; - JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; + NSArray*frames = view.jc_frames; - view.jc_size_value = ((NSValue*)size.value).CGSizeValue; - view.jc_y_value = ((NSNumber*)top.value).doubleValue; - view.jc_centerX_value = ((NSNumber*)centerX.value).doubleValue; - - return; + JCLog(@"\n---%@--layoutByCenterXAndTopAndSize\n",view.jc_debug_key); + + //1. size + SET_SIZE + + //2. top + SET_TOP + + //3. centerX + SET_CENTER_X + + + return YES; } + + return NO; +} + +// 5. centerX and bottom and size ++ (BOOL)layoutByCenterXAndBottomAndSize:(UIView*)view{ - // 5. centerX and bottom and size + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; if ((frameTypes & JCFrameTypeCenterX) &&(frameTypes & JCFrameTypeBottom) &&(frameTypes & JCFrameTypeSize)) { - JCFrame *centerX = [self filterFrameIn:frames frameType:(JCFrameTypeCenterX)]; - JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)]; - JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; + JCLog(@"\n---%@--layoutByCenterXAndBottomAndSize\n",view.jc_debug_key); - view.jc_size_value = ((NSValue*)size.value).CGSizeValue; - view.jc_centerX_value = ((NSNumber*)centerX.value).doubleValue; - view.jc_y_value = view.superview.jc_height_value/*父容器高度*/ - view.jc_height_value/*高度*/ + ((NSNumber*)bottom.value).doubleValue/*距离父容器底边距,一般为负数*/; + //1. size + SET_SIZE - return; + //2. centerX + SET_CENTER_X + + //3. bottom + SET_BOTTOM + + return NO; } + return NO; +} + +// 6. centerY and left and size ++ (BOOL)layoutByCenterYAndLeftAndSize:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; - // 6. centerY and left and size if ((frameTypes & JCFrameTypeCenterY) &&(frameTypes & JCFrameTypeLeft) &&(frameTypes & JCFrameTypeSize)) { - JCFrame *centerY = [self filterFrameIn:frames frameType:(JCFrameTypeCenterY)]; - JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)]; - JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; + JCLog(@"\n---%@--layoutByCenterYAndLeftAndSize\n",view.jc_debug_key); - view.jc_size_value = ((NSValue*)size.value).CGSizeValue; - view.jc_x_value = ((NSNumber*)left.value).doubleValue; - view.jc_y_value = ((NSNumber*)centerY.value).doubleValue - view.jc_height_value/2; + NSArray*frames = view.jc_frames; - return; + //1. size + SET_SIZE + + //2. centerY + SET_CENTER_Y + + //3. left + SET_LEFT + + return YES; } + return NO; +} + +// 7. centerY and right and size ++ (BOOL)layoutByCenterYAndRightAndSize:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; - // 7. centerY and right and size if ((frameTypes & JCFrameTypeCenterY) &&(frameTypes & JCFrameTypeRight) &&(frameTypes & JCFrameTypeSize)) { - JCFrame *centerY = [self filterFrameIn:frames frameType:(JCFrameTypeCenterY)]; - JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)]; - JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; + JCLog(@"\n---%@--layoutByCenterYAndRightAndSize\n",view.jc_debug_key); - view.jc_size_value = ((NSValue*)size.value).CGSizeValue; - view.jc_y_value = ((NSNumber*)centerY.value).doubleValue - view.jc_height_value/2; - view.jc_x_value = view.superview.jc_width_value/*父容器宽度*/-view.jc_width_value/*宽度*/+((NSNumber*)right.value).doubleValue/*右边距,负数*/; + //1. size + SET_SIZE - return; + //2. centerY + SET_CENTER_Y + + //3. right + SET_RIGHT + + return YES; } - // 8. left and top and size + return NO; +} + +#pragma mark - 只有 size +// 8. left and top and size ++ (BOOL)layoutByLeftAndTopAndSize:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeLeft) &&(frameTypes & JCFrameTypeTop) &&(frameTypes & JCFrameTypeSize)) { - JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)]; - JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)]; - JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; + JCLog(@"\n---%@--layoutByLeftAndTopAndSize\n",view.jc_debug_key); - view.jc_size_value = ((NSValue*)size.value).CGSizeValue; - view.jc_y_value = ((NSNumber*)top.value).doubleValue; - view.jc_x_value = ((NSNumber*)left.value).doubleValue; + //1. size + SET_SIZE - return; + //2. left + SET_LEFT + + //3. top + SET_TOP + + return YES; } + return NO; +} + +// 9. left and bottom and size ++ (BOOL)layoutByLeftAndBottomAndSize:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; - // 9. left and bottom and size if ((frameTypes & JCFrameTypeLeft) &&(frameTypes & JCFrameTypeBottom) &&(frameTypes & JCFrameTypeSize)) { - JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)]; - JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)]; - JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; + JCLog(@"\n---%@--layoutByLeftAndBottomAndSize\n",view.jc_debug_key); - view.jc_size_value = ((NSValue*)size.value).CGSizeValue; - view.jc_x_value = ((NSNumber*)left.value).doubleValue; - view.jc_y_value = view.superview.jc_height_value/*父容器高度*/ - view.jc_height_value/*高度*/ + ((NSNumber*)bottom.value).doubleValue/*距离父容器底边距,一般为负数*/; + //1. size + SET_SIZE - return; + //2. left + SET_LEFT + + //3. bottom + SET_BOTTOM + + return YES; } + return NO; +} + +// 10. right and top and size ++ (BOOL)layoutByRightAndTopAndSize:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; - // 10. right and top and size if ((frameTypes & JCFrameTypeRight) &&(frameTypes & JCFrameTypeTop) &&(frameTypes & JCFrameTypeSize)) { - JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)]; - JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)]; - JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; + JCLog(@"\n---%@--layoutByRightAndTopAndSize\n",view.jc_debug_key); - view.jc_size_value = ((NSValue*)size.value).CGSizeValue; - view.jc_y_value = ((NSNumber*)top.value).doubleValue; - view.jc_x_value = view.superview.jc_width_value/*父容器宽度*/-view.jc_width_value/*宽度*/+((NSNumber*)right.value).doubleValue/*右边距,负数*/; + //1. size + SET_SIZE - return; + //2. top + SET_TOP + + //3. right + SET_RIGHT + return YES; } - // 11. right and bottom and size + return NO; +} + +// 11. right and bottom and size ++ (BOOL)layoutByRightAndBottomAndSize:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeRight) &&(frameTypes & JCFrameTypeBottom) &&(frameTypes & JCFrameTypeSize)) { - JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)]; - JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)]; - JCFrame *size = [self filterFrameIn:frames frameType:(JCFrameTypeSize)]; + JCLog(@"\n---%@--layoutByRightAndBottomAndSize\n",view.jc_debug_key); - view.jc_size_value = ((NSValue*)size.value).CGSizeValue; - view.jc_x_value = view.superview.jc_width_value/*父容器宽度*/-view.jc_width_value/*宽度*/+((NSNumber*)right.value).doubleValue/*右边距,负数*/; - view.jc_y_value = view.superview.jc_height_value/*父容器高度*/ - view.jc_height_value/*高度*/ + ((NSNumber*)bottom.value).doubleValue/*距离父容器底边距,一般为负数*/; + //1. size + SET_SIZE - return; + //2. right + SET_RIGHT + + //3. bottom + SET_BOTTOM + + return YES; } - // 12. centerX and centerY and width and height + return NO; +} + +#pragma mark - 含有centerX 或 centerY +// 12. centerX and centerY and width and height ++ (BOOL)layoutByCenterXAndCenterYAndWidthAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeCenterX) &&(frameTypes & JCFrameTypeCenterY) &&(frameTypes & JCFrameTypeWidth) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *centerX = [self filterFrameIn:frames frameType:(JCFrameTypeCenterX)]; - JCFrame *centerY = [self filterFrameIn:frames frameType:(JCFrameTypeCenterY)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByCenterXAndCenterYAndWidthAndHeight\n",view.jc_debug_key); - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; - view.jc_centerX_value = ((NSNumber*)centerX.value).doubleValue; - view.jc_centerY_value = ((NSNumber*)centerY.value).doubleValue; + //1. width + SET_WIDTH - return; + //2. height + SET_HEIGHT + + //3. centerX + SET_CENTER_X + + //4. centerY + SET_CENTER_Y + + return YES; } + + + return NO; +} + +// 13. centerX and top and width and height ++ (BOOL)layoutByCenterXAndTopAndWidthAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; - // 13. centerX and top and width and height if ((frameTypes & JCFrameTypeCenterX) &&(frameTypes & JCFrameTypeTop) &&(frameTypes & JCFrameTypeWidth) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *centerX = [self filterFrameIn:frames frameType:(JCFrameTypeCenterX)]; - JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByCenterXAndTopAndWidthAndHeight\n",view.jc_debug_key); - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; - view.jc_centerX_value = ((NSNumber*)centerX.value).doubleValue; - view.jc_y_value = ((NSNumber*)top.value).doubleValue; + //1. width + SET_WIDTH - return; + //2. height + SET_HEIGHT + + //3. centerX + SET_CENTER_X + + //4. top + SET_TOP + + return YES; } - // 14. centerX and bottom and width and height + + return NO; +} + +// 14. centerX and bottom and width and height ++ (BOOL)layoutByCenterXAndBottomAndWidthAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeCenterX) &&(frameTypes & JCFrameTypeBottom) &&(frameTypes & JCFrameTypeWidth) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *centerX = [self filterFrameIn:frames frameType:(JCFrameTypeCenterX)]; - JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByCenterXAndBottomAndWidthAndHeight\n",view.jc_debug_key); - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; - view.jc_centerX_value = ((NSNumber*)centerX.value).doubleValue; - view.jc_y_value = view.superview.jc_height_value/*父容器高度*/ - view.jc_height_value/*高度*/ + ((NSNumber*)bottom.value).doubleValue/*距离父容器底边距,一般为负数*/; + //1. width + SET_WIDTH - return; + //2. height + SET_HEIGHT + + //3. centerX + SET_CENTER_X + + //4. bottom + SET_BOTTOM + + return YES; } - // 15. centerY and left and width and height + + return NO; +} + +// 15. centerY and left and width and height ++ (BOOL)layoutByCenterYAndLeftAndWidthAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeCenterY) &&(frameTypes & JCFrameTypeLeft) &&(frameTypes & JCFrameTypeWidth) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *centerY = [self filterFrameIn:frames frameType:(JCFrameTypeCenterY)]; - JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByCenterYAndLeftAndWidthAndHeight\n",view.jc_debug_key); - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; - view.jc_centerY_value = ((NSNumber*)centerY.value).doubleValue; - view.jc_x_value = ((NSNumber*)left.value).doubleValue; + //1. width + SET_WIDTH - return; + //2. height + SET_HEIGHT + + //3. left + SET_LEFT + + //4. centerY + SET_CENTER_Y + + return YES; } - // 16. centerY and right and width and height + + return NO; +} + +// 16. centerY and right and width and height ++ (BOOL)layoutByCenterYAndRightAndWidthAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeCenterY) &&(frameTypes & JCFrameTypeRight) &&(frameTypes & JCFrameTypeWidth) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *centerY = [self filterFrameIn:frames frameType:(JCFrameTypeCenterY)]; - JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByCenterYAndRightAndWidthAndHeight\n",view.jc_debug_key); - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; - view.jc_centerY_value = ((NSNumber*)centerY.value).doubleValue; - view.jc_x_value = view.superview.jc_width_value/*父容器宽度*/-view.jc_width_value/*宽度*/+((NSNumber*)right.value).doubleValue/*右边距,负数*/; + //1. width + SET_WIDTH - return; + //2. height + SET_HEIGHT + + //3. centerY + SET_CENTER_Y + + //4. right + SET_RIGHT + + return YES; } - // 含有2条边界值,2个尺寸 - // 17. left and top and width and height + return NO; +} + +#pragma mark - 含有2条边界值,2个尺寸的组合 +// 17. left and top and width and height ++ (BOOL)layoutByLeftAndTopAndWidthAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeLeft) &&(frameTypes & JCFrameTypeTop) &&(frameTypes & JCFrameTypeWidth) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)]; - JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByLeftAndTopAndWidthAndHeight\n",view.jc_debug_key); - view.jc_x_value = ((NSNumber*)left.value).doubleValue; - view.jc_y_value = ((NSNumber*)top.value).doubleValue; - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; + //1. width + SET_WIDTH - return; + //2. height + SET_HEIGHT + + //3. top + SET_TOP + + //4. left + SET_LEFT + + return YES; } - // 18. left and bottom and width and height + return NO; +} + +// 18. left and bottom and width and height ++ (BOOL)layoutByLeftAndBottomAndWidthAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeLeft) &&(frameTypes & JCFrameTypeBottom) &&(frameTypes & JCFrameTypeWidth) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)]; - JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByLeftAndBottomAndWidthAndHeight\n",view.jc_debug_key); - view.jc_x_value = ((NSNumber*)left.value).doubleValue; - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; - view.jc_y_value = view.superview.jc_height_value/*父容器高度*/ - view.jc_height_value/*高度*/ + ((NSNumber*)bottom.value).doubleValue/*底部边距*/; + //1. width + SET_WIDTH - return; + //2. height + SET_HEIGHT + + //3. bottom + SET_BOTTOM + + //4. left + SET_LEFT + + + return YES; } - // 19. right and top and width and height + return NO; +} + +// 19. right and top and width and height ++ (BOOL)layoutByRightAndTopAndWidthAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeRight) &&(frameTypes & JCFrameTypeTop) &&(frameTypes & JCFrameTypeWidth) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)]; - JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByRightAndTopAndWidthAndHeight\n",view.jc_debug_key); - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; - view.jc_x_value = view.superview.jc_width_value/*父容器宽度*/ - view.jc_width_value/*宽度*/ + ((NSNumber*)right.value).doubleValue/*右边距*/; - view.jc_y_value = ((NSNumber*)top.value).doubleValue; + //1. width + SET_WIDTH - return; + //2. height + SET_HEIGHT + + //3. right + SET_RIGHT + + //4. top + SET_TOP + + return YES; } - // 20. right and bottom and width and height + return NO; +} + +// 20. right and bottom and width and height ++ (BOOL)layoutByRightAndBottomAndWidthAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeRight) &&(frameTypes & JCFrameTypeBottom) &&(frameTypes & JCFrameTypeWidth) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)]; - JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByRightAndBottomAndWidthAndHeight\n",view.jc_debug_key); - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; - view.jc_x_value = view.superview.jc_width_value/*父容器宽度*/ - view.jc_width_value/*宽度*/ + ((NSNumber*)right.value).doubleValue/*右边距*/; - view.jc_y_value = view.superview.jc_height_value/*父容器高度*/ - view.jc_height_value/*高度*/ + ((NSNumber*)bottom.value).doubleValue/*底部边距*/; + //1. width + SET_WIDTH - return; + //2. height + SET_HEIGHT + + //3. right + SET_RIGHT + + //4. bottom + SET_BOTTOM + + return YES; } + + return NO; - // 含有3条边距值,1个尺寸值 - // 21. left and right and top and height +} + +#pragma mark - 含有3条边距值,1个尺寸值的组合 +// 21. left and right and top and height ++ (BOOL)layoutByLeftAndRightAndTopAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeLeft) &&(frameTypes & JCFrameTypeRight) &&(frameTypes & JCFrameTypeTop) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)]; - JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)]; - JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByLeftAndRightAndTopAndHeight\n",view.jc_debug_key); - view.jc_x_value = ((NSNumber*)left.value).doubleValue; - view.jc_y_value = ((NSNumber*)top.value).doubleValue; - view.jc_width_value = view.superview.jc_width_value/*父容器宽度*/-view.jc_x_value/*左边距*/+((NSNumber*)right.value).doubleValue/*右边距,负数*/; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; + //1. height + SET_HEIGHT - return; + //2. top + SET_TOP + + //3. left and right + SET_LEFT_RIGHT + + return YES; } + + return NO; + +} +// 22. left and right and bottom and height ++ (BOOL)layoutByLeftAndRightAndBottomAndHeight:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; - // 22. left and right and bottom and height if ((frameTypes & JCFrameTypeLeft) &&(frameTypes & JCFrameTypeRight) &&(frameTypes & JCFrameTypeBottom) &&(frameTypes & JCFrameTypeHeight)) { - JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)]; - JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)]; - JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)]; - JCFrame *height = [self filterFrameIn:frames frameType:(JCFrameTypeHeight)]; + JCLog(@"\n---%@--layoutByLeftAndRightAndBottomAndHeight\n",view.jc_debug_key); - view.jc_x_value = ((NSNumber*)left.value).doubleValue; - view.jc_height_value = ((NSNumber*)height.value).doubleValue; - view.jc_width_value = view.superview.jc_width_value/*父容器宽度*/-view.jc_x_value/*左边距*/+((NSNumber*)right.value).doubleValue/*右边距,负数*/; - view.jc_y_value = view.superview.jc_height_value/*父容器高度*/-view.jc_height_value/*高度*/+((NSNumber*)bottom.value).doubleValue/*底边距,负数*/; + //1. height + SET_HEIGHT - return; + //2. bottom + SET_BOTTOM + + //3. left and right + SET_LEFT_RIGHT + + return YES; } - // 23. left and top and bottom and width + return NO; + +} + +// 23. left and top and bottom and width ++ (BOOL)layoutByLeftAndTopAndBottomAndWidth:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; + if ((frameTypes & JCFrameTypeLeft) &&(frameTypes & JCFrameTypeTop) &&(frameTypes & JCFrameTypeBottom) &&(frameTypes & JCFrameTypeWidth)) { - JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)]; - JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)]; - JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; + JCLog(@"\n---%@--layoutByLeftAndTopAndBottomAndWidth\n",view.jc_debug_key); - view.jc_x_value = ((NSNumber*)left.value).doubleValue; - view.jc_y_value = ((NSNumber*)top.value).doubleValue; - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = view.superview.jc_height_value/*父容器高度*/ - view.jc_y_value/*顶边距*/ + ((NSNumber*)bottom.value).doubleValue/*底边距*/; + //1. width + SET_WIDTH - return; + //2. left + SET_LEFT + + //3. top and bottom + SET_TOP_BOTTOM + + return YES; } + + return NO; + +} +// 24. right and top and bottom and width ++ (BOOL)layoutByRightAndTopAndBottomAndWidth:(UIView*)view{ + + JCFrameType frameTypes = view.jc_settedFrameTypes; + + NSArray*frames = view.jc_frames; - // 24. right and top and bottom and width if ((frameTypes & JCFrameTypeRight) &&(frameTypes & JCFrameTypeTop) &&(frameTypes & JCFrameTypeBottom) &&(frameTypes & JCFrameTypeWidth)) { - JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)]; - JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)]; - JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)]; - JCFrame *width = [self filterFrameIn:frames frameType:(JCFrameTypeWidth)]; + JCLog(@"\n---%@--layoutByRightAndTopAndBottomAndWidth\n",view.jc_debug_key); - view.jc_y_value = ((NSNumber*)top.value).doubleValue; - view.jc_width_value = ((NSNumber*)width.value).doubleValue; - view.jc_height_value = view.superview.jc_height_value/*父容器高度*/ - view.jc_y_value/*顶边距*/ + ((NSNumber*)bottom.value).doubleValue/*底边距*/; - view.jc_x_value = view.superview.jc_width_value/*父容器宽度*/ - view.jc_width_value/*宽度*/ + ((NSNumber*)right.value).doubleValue/*右边距*/; + //1. width + SET_WIDTH - return; + //2. right + SET_RIGHT + + //3. top and bottom + SET_TOP_BOTTOM + + return YES; } + + return NO; + +} + +#pragma mark - 含有4条边距值 +// 25. left and right and top and bottom ++ (BOOL)layoutByLeftAndRightAndTopAndBottom:(UIView*)view{ + JCFrameType frameTypes = view.jc_settedFrameTypes; + NSArray*frames = view.jc_frames; - // 含有4条边距值 - // 25. left and right and top and bottom if ((frameTypes & JCFrameTypeLeft) &&(frameTypes & JCFrameTypeRight) &&(frameTypes & JCFrameTypeTop) &&(frameTypes & JCFrameTypeBottom)) { - JCFrame *left = [self filterFrameIn:frames frameType:(JCFrameTypeLeft)]; - JCFrame *right = [self filterFrameIn:frames frameType:(JCFrameTypeRight)]; - JCFrame *top = [self filterFrameIn:frames frameType:(JCFrameTypeTop)]; - JCFrame *bottom = [self filterFrameIn:frames frameType:(JCFrameTypeBottom)]; + JCLog(@"\n---%@--layoutByLeftAndRightAndTopAndBottom\n",view.jc_debug_key); - view.jc_x_value = ((NSNumber*)left.value).doubleValue; - view.jc_y_value = ((NSNumber*)top.value).doubleValue; - view.jc_width_value = view.superview.jc_width_value/*父容器宽度*/-view.jc_x_value/*左边距*/+((NSNumber*)right.value).doubleValue/*右边距,负数*/; - view.jc_height_value = view.superview.jc_height_value/*父容器高度*/-view.jc_y_value/*顶边距*/+((NSNumber*)bottom.value).doubleValue/*右边距,负数*/; + //1. left and right + SET_LEFT_RIGHT - return; + //2. top and bottom + SET_TOP_BOTTOM + + return YES; } - + + return NO; + } +#pragma mark - 过滤的公共方法 + (JCFrame*)filterFrameIn:(NSArray*)collection frameType:(JCFrameType)frameType{ - NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"frameType=%zd",frameType]]; + NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(JCFrame *frame, id obj) { + return frame.frameAttr.currentFrameType == frameType; + }]; NSArray *result = [collection filteredArrayUsingPredicate:predicate]; - return (result && result.count > 0) ? result.firstObject : nil; + JCFrame *frame = (result && result.count > 0) ? result.firstObject : nil; + //将Frame的actived标记为YES + frame.actived = YES; + return frame; } @end diff --git a/JCFrameLayout/JCFrameLayout/JCFrameLayout.h b/JCFrameLayout/JCFrameLayout/JCFrameLayout.h index 2dd4381..3b6b0c2 100644 --- a/JCFrameLayout/JCFrameLayout/JCFrameLayout.h +++ b/JCFrameLayout/JCFrameLayout/JCFrameLayout.h @@ -10,5 +10,6 @@ #define JCFrameLayout_h #import "UIView+JCFrameLayout.h" +#import "UIView+JCFrame.h" #endif /* JCFrameLayout_h */ diff --git a/JCFrameLayout/JCFrameLayout/JCFrameLayoutConst.h b/JCFrameLayout/JCFrameLayout/JCFrameLayoutConst.h index f2d07ed..e8ecf48 100644 --- a/JCFrameLayout/JCFrameLayout/JCFrameLayoutConst.h +++ b/JCFrameLayout/JCFrameLayout/JCFrameLayoutConst.h @@ -9,7 +9,7 @@ #ifndef JCFrameLayoutConst_h #define JCFrameLayoutConst_h -//#define NOLOG 1 +#define NOLOG 1 #ifdef NOLOG #define JCLog( s,...) diff --git a/JCFrameLayout/JCFrameLayout/JCFrameMake.m b/JCFrameLayout/JCFrameLayout/JCFrameMake.m index 9e7394b..404da63 100644 --- a/JCFrameLayout/JCFrameLayout/JCFrameMake.m +++ b/JCFrameLayout/JCFrameLayout/JCFrameMake.m @@ -18,11 +18,6 @@ @interface JCFrameMake () **/ @property (nonatomic,weak) UIView *view; -/** - * <#注释#> - **/ -@property (nonatomic,assign) JCFrameType frameTypes; - @end @implementation JCFrameMake @@ -74,25 +69,42 @@ - (JCFrame*)jcFrame:(JCFrame *)jcFrame createFrameWithframeType:(JCFrameType)fra } - (JCFrame *)createJCLayoutFrame:(JCFrameType)frameType{ - /** - 如果这个frameType已存在,则直接返回,反之创建 - */ - if (self.frameTypes & frameType) { - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"frameType=%d",frameType]; + + if (self.view.jc_settedFrameTypes & frameType) { + /** + 如果这个frameType已存在,则直接返回,反之创建 + */ + NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(JCFrame *frame, id obj) { + return frame.frameAttr.currentFrameType == frameType; + }]; NSArray *filterResult = [self.view.jc_frames filteredArrayUsingPredicate:predicate]; return filterResult.firstObject; + }else{ - self.frameTypes |= frameType; //将frameType标记为已存在 - JCFrame *frame = [[JCFrame alloc]initWithView:self.view frameType:frameType]; + + //1.将frameType标记为已存在 + self.view.jc_settedFrameTypes |= frameType; + + //2.创建JCFrameAttribute + JCFrameAttribute *frameAttribute = [[JCFrameAttribute alloc]initWithView:self.view frameType:frameType]; + + //3.创建JCFrame + JCFrame *frame = [[JCFrame alloc]initWithFrameAttribute:frameAttribute]; + + //4.设置JCFrame代理 frame.delegate = self; + + //5.将JCFrame添加至UIView的jc_frames集合中 + [self.view.jc_frames addObject:frame]; + return frame; } } - (void)executeLayout{ - [JCFrameExecutor executeWithView:self.view - frames:self.view.jc_frames - frameTypes:self.frameTypes]; + [JCFrameExecutor executeWithView:self.view]; + JCLog(@"--frames = %@",self.view.jc_frames); + } - (void)dealloc{ diff --git a/JCFrameLayout/JCFrameLayout/UIView+JCFrame.h b/JCFrameLayout/JCFrameLayout/UIView+JCFrame.h index ead962a..8b3a88f 100644 --- a/JCFrameLayout/JCFrameLayout/UIView+JCFrame.h +++ b/JCFrameLayout/JCFrameLayout/UIView+JCFrame.h @@ -8,8 +8,11 @@ #import +#import "JCFrameAttribute.h" + @interface UIView (JCFrame) +#pragma mark - getter and setter - (void)setJc_x_value:(CGFloat)value; - (CGFloat)jc_x_value; @@ -34,5 +37,29 @@ - (void)setJc_size_value:(CGSize)value; - (CGSize)jc_size_value; +#pragma mark - getter only +- (CGFloat)jc_right_value; +- (CGFloat)jc_bottom_value; + +- (JCFrameAttribute*)jc_left; +- (JCFrameAttribute*)jc_top; +- (JCFrameAttribute*)jc_right; +- (JCFrameAttribute*)jc_bottom; +- (JCFrameAttribute*)jc_width; +- (JCFrameAttribute*)jc_height; +- (JCFrameAttribute*)jc_centerX; +- (JCFrameAttribute*)jc_centerY; +- (JCFrameAttribute*)jc_center; +- (JCFrameAttribute*)jc_size; + +//给UIView设置一个key值,用于方便调试 +@property (nonatomic,copy) NSString *jc_debug_key; + - (NSMutableArray *)jc_frames; +/** + 已经设置过得布局属性,通过位运算来组合 + */ +- (JCFrameType)jc_settedFrameTypes; +- (void)setJc_settedFrameTypes:(JCFrameType)frameType; + @end diff --git a/JCFrameLayout/JCFrameLayout/UIView+JCFrame.m b/JCFrameLayout/JCFrameLayout/UIView+JCFrame.m index 18a0dda..62f827d 100644 --- a/JCFrameLayout/JCFrameLayout/UIView+JCFrame.m +++ b/JCFrameLayout/JCFrameLayout/UIView+JCFrame.m @@ -9,8 +9,12 @@ #import "UIView+JCFrame.h" #import +static char debugkey; +static char settedFrameTypesKey; + @implementation UIView (JCFrame) +#pragma mark - getter and setter - (void)setJc_x_value:(CGFloat)value{ CGRect frame = self.frame; frame.origin.x = value; @@ -81,6 +85,55 @@ - (CGSize)jc_size_value{ return self.frame.size; } +#pragma mark - getter only +- (CGFloat)jc_right_value{ + return self.jc_x_value + self.jc_width_value; +} +- (CGFloat)jc_bottom_value{ + return self.jc_y_value + self.jc_height_value; +} + + + +- (JCFrameAttribute*)jc_left{ + return [[JCFrameAttribute alloc]initWithView:self frameType:(JCFrameTypeLeft)]; +} +- (JCFrameAttribute*)jc_top{ + return [[JCFrameAttribute alloc]initWithView:self frameType:(JCFrameTypeTop)]; +} +- (JCFrameAttribute*)jc_right{ + return [[JCFrameAttribute alloc]initWithView:self frameType:(JCFrameTypeRight)]; +} +- (JCFrameAttribute*)jc_bottom{ + return [[JCFrameAttribute alloc]initWithView:self frameType:(JCFrameTypeBottom)]; +} +- (JCFrameAttribute*)jc_width{ + return [[JCFrameAttribute alloc]initWithView:self frameType:(JCFrameTypeWidth)]; +} +- (JCFrameAttribute*)jc_height{ + return [[JCFrameAttribute alloc]initWithView:self frameType:(JCFrameTypeHeight)]; +} +- (JCFrameAttribute*)jc_centerX{ + return [[JCFrameAttribute alloc]initWithView:self frameType:(JCFrameTypeCenterX)]; +} +- (JCFrameAttribute*)jc_centerY{ + return [[JCFrameAttribute alloc]initWithView:self frameType:(JCFrameTypeCenterY)]; +} +- (JCFrameAttribute*)jc_center{ + return [[JCFrameAttribute alloc]initWithView:self frameType:(JCFrameTypeCenter)]; +} +- (JCFrameAttribute*)jc_size{ + return [[JCFrameAttribute alloc]initWithView:self frameType:(JCFrameTypeSize)]; +} + +- (void)setJc_debug_key:(NSString *)key{ + objc_setAssociatedObject(self, &debugkey, key, OBJC_ASSOCIATION_COPY_NONATOMIC); +} +- (NSString *)jc_debug_key{ + NSString *key = objc_getAssociatedObject(self, &debugkey); + return key ? key : @""; +} + - (NSMutableArray *)jc_frames{ static char key; NSMutableArray *array = (NSMutableArray*)objc_getAssociatedObject(self, &key); @@ -90,4 +143,20 @@ - (NSMutableArray *)jc_frames{ } return array; } + +/** + 已经设置过得布局属性,通过位运算来组合 + */ +- (JCFrameType)jc_settedFrameTypes{ + NSNumber *settedFrameTypes = ((NSNumber*)objc_getAssociatedObject(self, &settedFrameTypesKey)); + if (!settedFrameTypes) { + settedFrameTypes = [NSNumber numberWithInt:0]; + objc_setAssociatedObject(self, &settedFrameTypesKey, settedFrameTypes, OBJC_ASSOCIATION_ASSIGN); + } + return settedFrameTypes.integerValue; +} +- (void)setJc_settedFrameTypes:(JCFrameType)frameType{ + NSNumber *settedFrameTypes = [NSNumber numberWithInt:frameType]; + objc_setAssociatedObject(self, &settedFrameTypesKey, settedFrameTypes, OBJC_ASSOCIATION_ASSIGN); +} @end diff --git a/JCFrameLayout/JCFrameLayout/UIView+JCFrameLayout.h b/JCFrameLayout/JCFrameLayout/UIView+JCFrameLayout.h index 44eceb6..24ab49d 100644 --- a/JCFrameLayout/JCFrameLayout/UIView+JCFrameLayout.h +++ b/JCFrameLayout/JCFrameLayout/UIView+JCFrameLayout.h @@ -10,10 +10,16 @@ #import "JCFrameMake.h" +#define JC_SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) +#define JC_SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) + @interface UIView (JCFrameLayout) - (void)jc_makeLayout:(void(^)(JCFrameMake *make))block; - +/** + 重新布局 + */ +- (void)jc_updateLayout; @end diff --git a/JCFrameLayout/JCFrameLayout/UIView+JCFrameLayout.m b/JCFrameLayout/JCFrameLayout/UIView+JCFrameLayout.m index 698a9e3..33b7c76 100644 --- a/JCFrameLayout/JCFrameLayout/UIView+JCFrameLayout.m +++ b/JCFrameLayout/JCFrameLayout/UIView+JCFrameLayout.m @@ -7,10 +7,18 @@ // #import "UIView+JCFrameLayout.h" +#import "UIView+JCFrame.h" + +#import "JCFrameExecutor.h" @implementation UIView (JCFrameLayout) - (void)jc_makeLayout:(void (^)(JCFrameMake *))block{ + + //清空已存在的属性 + [self.jc_frames removeAllObjects]; + self.jc_settedFrameTypes = 0; + //创建Frame构建器 JCFrameMake *make = [[JCFrameMake alloc]initWithView:self]; //生成frame @@ -19,4 +27,14 @@ - (void)jc_makeLayout:(void (^)(JCFrameMake *))block{ [make executeLayout]; } + +/** + 重新布局 + */ +- (void)jc_updateLayout{ + [JCFrameExecutor executeWithView:self]; + JCLog(@"--frames = %@",self.jc_frames); +} + + @end diff --git a/JCFrameLayout/Masonry/MASCompositeConstraint.h b/JCFrameLayout/Masonry/MASCompositeConstraint.h deleted file mode 100755 index 934c6f1..0000000 --- a/JCFrameLayout/Masonry/MASCompositeConstraint.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// MASCompositeConstraint.h -// Masonry -// -// Created by Jonas Budelmann on 21/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "MASConstraint.h" -#import "MASUtilities.h" - -/** - * A group of MASConstraint objects - */ -@interface MASCompositeConstraint : MASConstraint - -/** - * Creates a composite with a predefined array of children - * - * @param children child MASConstraints - * - * @return a composite constraint - */ -- (id)initWithChildren:(NSArray *)children; - -@end diff --git a/JCFrameLayout/Masonry/MASCompositeConstraint.m b/JCFrameLayout/Masonry/MASCompositeConstraint.m deleted file mode 100755 index ac673ac..0000000 --- a/JCFrameLayout/Masonry/MASCompositeConstraint.m +++ /dev/null @@ -1,177 +0,0 @@ -// -// MASCompositeConstraint.m -// Masonry -// -// Created by Jonas Budelmann on 21/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "MASCompositeConstraint.h" -#import "MASConstraint+Private.h" - -@interface MASCompositeConstraint () - -@property (nonatomic, strong) id mas_key; -@property (nonatomic, strong) NSMutableArray *childConstraints; - -@end - -@implementation MASCompositeConstraint - -- (id)initWithChildren:(NSArray *)children { - self = [super init]; - if (!self) return nil; - - _childConstraints = [children mutableCopy]; - for (MASConstraint *constraint in _childConstraints) { - constraint.delegate = self; - } - - return self; -} - -#pragma mark - MASConstraintDelegate - -- (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint { - NSUInteger index = [self.childConstraints indexOfObject:constraint]; -// NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint); - [self.childConstraints replaceObjectAtIndex:index withObject:replacementConstraint]; -} - -- (MASConstraint *)constraint:(MASConstraint __unused *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { - id strongDelegate = self.delegate; - MASConstraint *newConstraint = [strongDelegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; - newConstraint.delegate = self; - [self.childConstraints addObject:newConstraint]; - return newConstraint; -} - -#pragma mark - NSLayoutConstraint multiplier proxies - -- (MASConstraint * (^)(CGFloat))multipliedBy { - return ^id(CGFloat multiplier) { - for (MASConstraint *constraint in self.childConstraints) { - constraint.multipliedBy(multiplier); - } - return self; - }; -} - -- (MASConstraint * (^)(CGFloat))dividedBy { - return ^id(CGFloat divider) { - for (MASConstraint *constraint in self.childConstraints) { - constraint.dividedBy(divider); - } - return self; - }; -} - -#pragma mark - MASLayoutPriority proxy - -- (MASConstraint * (^)(MASLayoutPriority))priority { - return ^id(MASLayoutPriority priority) { - for (MASConstraint *constraint in self.childConstraints) { - constraint.priority(priority); - } - return self; - }; -} - -#pragma mark - NSLayoutRelation proxy - -- (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { - return ^id(id attr, NSLayoutRelation relation) { - for (MASConstraint *constraint in self.childConstraints.copy) { - constraint.equalToWithRelation(attr, relation); - } - return self; - }; -} - -#pragma mark - attribute chaining - -- (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { - [self constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; - return self; -} - -#pragma mark - Animator proxy - -#if TARGET_OS_MAC && !TARGET_OS_IPHONE - -- (MASConstraint *)animator { - for (MASConstraint *constraint in self.childConstraints) { - [constraint animator]; - } - return self; -} - -#endif - -#pragma mark - debug helpers - -- (MASConstraint * (^)(id))key { - return ^id(id key) { - self.mas_key = key; - int i = 0; - for (MASConstraint *constraint in self.childConstraints) { - constraint.key([NSString stringWithFormat:@"%@[%d]", key, i++]); - } - return self; - }; -} - -#pragma mark - NSLayoutConstraint constant setters - -- (void)setInsets:(MASEdgeInsets)insets { - for (MASConstraint *constraint in self.childConstraints) { - constraint.insets = insets; - } -} - -- (void)setOffset:(CGFloat)offset { - for (MASConstraint *constraint in self.childConstraints) { - constraint.offset = offset; - } -} - -- (void)setSizeOffset:(CGSize)sizeOffset { - for (MASConstraint *constraint in self.childConstraints) { - constraint.sizeOffset = sizeOffset; - } -} - -- (void)setCenterOffset:(CGPoint)centerOffset { - for (MASConstraint *constraint in self.childConstraints) { - constraint.centerOffset = centerOffset; - } -} - -#pragma mark - MASConstraint - -- (void)activate { - for (MASConstraint *constraint in self.childConstraints) { - [constraint activate]; - } -} - -- (void)deactivate { - for (MASConstraint *constraint in self.childConstraints) { - [constraint deactivate]; - } -} - -- (void)install { - for (MASConstraint *constraint in self.childConstraints) { - constraint.updateExisting = self.updateExisting; - [constraint install]; - } -} - -- (void)uninstall { - for (MASConstraint *constraint in self.childConstraints) { - [constraint uninstall]; - } -} - -@end diff --git a/JCFrameLayout/Masonry/MASConstraint+Private.h b/JCFrameLayout/Masonry/MASConstraint+Private.h deleted file mode 100755 index ee0fd96..0000000 --- a/JCFrameLayout/Masonry/MASConstraint+Private.h +++ /dev/null @@ -1,66 +0,0 @@ -// -// MASConstraint+Private.h -// Masonry -// -// Created by Nick Tymchenko on 29/04/14. -// Copyright (c) 2014 cloudling. All rights reserved. -// - -#import "MASConstraint.h" - -@protocol MASConstraintDelegate; - - -@interface MASConstraint () - -/** - * Whether or not to check for an existing constraint instead of adding constraint - */ -@property (nonatomic, assign) BOOL updateExisting; - -/** - * Usually MASConstraintMaker but could be a parent MASConstraint - */ -@property (nonatomic, weak) id delegate; - -/** - * Based on a provided value type, is equal to calling: - * NSNumber - setOffset: - * NSValue with CGPoint - setPointOffset: - * NSValue with CGSize - setSizeOffset: - * NSValue with MASEdgeInsets - setInsets: - */ -- (void)setLayoutConstantWithValue:(NSValue *)value; - -@end - - -@interface MASConstraint (Abstract) - -/** - * Sets the constraint relation to given NSLayoutRelation - * returns a block which accepts one of the following: - * MASViewAttribute, UIView, NSValue, NSArray - * see readme for more details. - */ -- (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation; - -/** - * Override to set a custom chaining behaviour - */ -- (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute; - -@end - - -@protocol MASConstraintDelegate - -/** - * Notifies the delegate when the constraint needs to be replaced with another constraint. For example - * A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks - */ -- (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint; - -- (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute; - -@end diff --git a/JCFrameLayout/Masonry/MASConstraint.h b/JCFrameLayout/Masonry/MASConstraint.h deleted file mode 100755 index 8dce1fd..0000000 --- a/JCFrameLayout/Masonry/MASConstraint.h +++ /dev/null @@ -1,118 +0,0 @@ -// -// MASConstraint.h -// Masonry -// -// Created by Jonas Budelmann on 22/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "MASUtilities.h" - -/** - * Enables Constraints to be created with chainable syntax - * Constraint can represent single NSLayoutConstraint (MASViewConstraint) - * or a group of NSLayoutConstraints (MASComposisteConstraint) - */ -@interface MASConstraint : NSObject - -#pragma mark - NSLayoutConstraint constant proxies -- (MASConstraint * (^)(MASEdgeInsets insets))insets; -- (MASConstraint * (^)(CGSize offset))sizeOffset; -- (MASConstraint * (^)(CGPoint offset))centerOffset; -- (MASConstraint * (^)(CGFloat offset))offset; -- (MASConstraint * (^)(NSValue *value))valueOffset; -- (MASConstraint * (^)(CGFloat multiplier))multipliedBy; -- (MASConstraint * (^)(CGFloat divider))dividedBy; - -#pragma mark - MASLayoutPriority proxies -- (MASConstraint * (^)(MASLayoutPriority priority))priority; -- (MASConstraint * (^)())priorityLow; -- (MASConstraint * (^)())priorityMedium; -- (MASConstraint * (^)())priorityHigh; - -#pragma mark - NSLayoutRelation proxies -- (MASConstraint * (^)(id attr))equalTo; -- (MASConstraint * (^)(id attr))greaterThanOrEqualTo; -- (MASConstraint * (^)(id attr))lessThanOrEqualTo; - -#pragma mark - Semantic properties -- (MASConstraint *)with; -- (MASConstraint *)and; - -#pragma mark - Chaining -- (MASConstraint *)left; -- (MASConstraint *)top; -- (MASConstraint *)right; -- (MASConstraint *)bottom; -- (MASConstraint *)leading; -- (MASConstraint *)trailing; -- (MASConstraint *)width; -- (MASConstraint *)height; -- (MASConstraint *)centerX; -- (MASConstraint *)centerY; -- (MASConstraint *)baseline; -- (MASConstraint *)leftMargin; -- (MASConstraint *)rightMargin; -- (MASConstraint *)topMargin; -- (MASConstraint *)bottomMargin; -- (MASConstraint *)leadingMargin; -- (MASConstraint *)trailingMargin; -- (MASConstraint *)centerXWithinMargins; -- (MASConstraint *)centerYWithinMargins; - - -#pragma mark - Abstract -- (MASConstraint * (^)(id key))key; -- (void)setInsets:(MASEdgeInsets)insets; -- (void)setSizeOffset:(CGSize)sizeOffset; -- (void)setCenterOffset:(CGPoint)centerOffset; -- (void)setOffset:(CGFloat)offset; - -- (void)activate; -- (void)deactivate; -- (void)install; -- (void)uninstall; - -@end - - -/** - * Convenience auto-boxing macros for MASConstraint methods. - * - * Defining MAS_SHORTHAND_GLOBALS will turn on auto-boxing for default syntax. - * A potential drawback of this is that the unprefixed macros will appear in global scope. - */ -#define mas_equalTo(...) equalTo(MASBoxValue((__VA_ARGS__))) -#define mas_greaterThanOrEqualTo(...) greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__))) -#define mas_lessThanOrEqualTo(...) lessThanOrEqualTo(MASBoxValue((__VA_ARGS__))) - -#define mas_offset(...) valueOffset(MASBoxValue((__VA_ARGS__))) - - -#ifdef MAS_SHORTHAND_GLOBALS - -#define equalTo(...) mas_equalTo(__VA_ARGS__) -#define greaterThanOrEqualTo(...) mas_greaterThanOrEqualTo(__VA_ARGS__) -#define lessThanOrEqualTo(...) mas_lessThanOrEqualTo(__VA_ARGS__) - -#define offset(...) mas_offset(__VA_ARGS__) - -#endif - - -@interface MASConstraint (AutoboxingSupport) - -/** - * Aliases to corresponding relation methods (for shorthand macros) - * Also needed to aid autocompletion - */ -- (MASConstraint * (^)(id attr))mas_equalTo; -- (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo; -- (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo; - -/** - * A dummy method to aid autocompletion - */ -- (MASConstraint * (^)(id offset))mas_offset; - -@end diff --git a/JCFrameLayout/Masonry/MASConstraint.m b/JCFrameLayout/Masonry/MASConstraint.m deleted file mode 100755 index 5dcc97b..0000000 --- a/JCFrameLayout/Masonry/MASConstraint.m +++ /dev/null @@ -1,281 +0,0 @@ -// -// MASConstraint.m -// Masonry -// -// Created by Nick Tymchenko on 1/20/14. -// - -#import "MASConstraint.h" -#import "MASConstraint+Private.h" - -#define MASMethodNotImplemented() \ - @throw [NSException exceptionWithName:NSInternalInconsistencyException \ - reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \ - userInfo:nil] - -@implementation MASConstraint - -#pragma mark - Init - -- (id)init { -// NSAssert(![self isMemberOfClass:[MASConstraint class]], @"MASConstraint is an abstract class, you should not instantiate it directly."); - return [super init]; -} - -#pragma mark - NSLayoutRelation proxies - -- (MASConstraint * (^)(id))equalTo { - return ^id(id attribute) { - return self.equalToWithRelation(attribute, NSLayoutRelationEqual); - }; -} - -- (MASConstraint * (^)(id))mas_equalTo { - return ^id(id attribute) { - return self.equalToWithRelation(attribute, NSLayoutRelationEqual); - }; -} - -- (MASConstraint * (^)(id))greaterThanOrEqualTo { - return ^id(id attribute) { - return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual); - }; -} - -- (MASConstraint * (^)(id))mas_greaterThanOrEqualTo { - return ^id(id attribute) { - return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual); - }; -} - -- (MASConstraint * (^)(id))lessThanOrEqualTo { - return ^id(id attribute) { - return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual); - }; -} - -- (MASConstraint * (^)(id))mas_lessThanOrEqualTo { - return ^id(id attribute) { - return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual); - }; -} - -#pragma mark - MASLayoutPriority proxies - -- (MASConstraint * (^)())priorityLow { - return ^id{ - self.priority(MASLayoutPriorityDefaultLow); - return self; - }; -} - -- (MASConstraint * (^)())priorityMedium { - return ^id{ - self.priority(MASLayoutPriorityDefaultMedium); - return self; - }; -} - -- (MASConstraint * (^)())priorityHigh { - return ^id{ - self.priority(MASLayoutPriorityDefaultHigh); - return self; - }; -} - -#pragma mark - NSLayoutConstraint constant proxies - -- (MASConstraint * (^)(MASEdgeInsets))insets { - return ^id(MASEdgeInsets insets){ - self.insets = insets; - return self; - }; -} - -- (MASConstraint * (^)(CGSize))sizeOffset { - return ^id(CGSize offset) { - self.sizeOffset = offset; - return self; - }; -} - -- (MASConstraint * (^)(CGPoint))centerOffset { - return ^id(CGPoint offset) { - self.centerOffset = offset; - return self; - }; -} - -- (MASConstraint * (^)(CGFloat))offset { - return ^id(CGFloat offset){ - self.offset = offset; - return self; - }; -} - -- (MASConstraint * (^)(NSValue *value))valueOffset { - return ^id(NSValue *offset) { - NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset); - [self setLayoutConstantWithValue:offset]; - return self; - }; -} - -- (MASConstraint * (^)(id offset))mas_offset { - // Will never be called due to macro - return nil; -} - -#pragma mark - NSLayoutConstraint constant setter - -- (void)setLayoutConstantWithValue:(NSValue *)value { - if ([value isKindOfClass:NSNumber.class]) { - self.offset = [(NSNumber *)value doubleValue]; - } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) { - CGPoint point; - [value getValue:&point]; - self.centerOffset = point; - } else if (strcmp(value.objCType, @encode(CGSize)) == 0) { - CGSize size; - [value getValue:&size]; - self.sizeOffset = size; - } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) { - MASEdgeInsets insets; - [value getValue:&insets]; - self.insets = insets; - } else { - NSAssert(NO, @"attempting to set layout constant with unsupported value: %@", value); - } -} - -#pragma mark - Semantic properties - -- (MASConstraint *)with { - return self; -} - -- (MASConstraint *)and { - return self; -} - -#pragma mark - Chaining - -- (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute __unused)layoutAttribute { - MASMethodNotImplemented(); -} - -- (MASConstraint *)left { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft]; -} - -- (MASConstraint *)top { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop]; -} - -- (MASConstraint *)right { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight]; -} - -- (MASConstraint *)bottom { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom]; -} - -- (MASConstraint *)leading { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading]; -} - -- (MASConstraint *)trailing { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing]; -} - -- (MASConstraint *)width { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth]; -} - -- (MASConstraint *)height { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight]; -} - -- (MASConstraint *)centerX { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX]; -} - -- (MASConstraint *)centerY { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY]; -} - -- (MASConstraint *)baseline { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; -} - -#if TARGET_OS_IPHONE - -- (MASConstraint *)leftMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin]; -} - -- (MASConstraint *)rightMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin]; -} - -- (MASConstraint *)topMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin]; -} - -- (MASConstraint *)bottomMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin]; -} - -- (MASConstraint *)leadingMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin]; -} - -- (MASConstraint *)trailingMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin]; -} - -- (MASConstraint *)centerXWithinMargins { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins]; -} - -- (MASConstraint *)centerYWithinMargins { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins]; -} - -#endif - -#pragma mark - Abstract - -- (MASConstraint * (^)(CGFloat multiplier))multipliedBy { MASMethodNotImplemented(); } - -- (MASConstraint * (^)(CGFloat divider))dividedBy { MASMethodNotImplemented(); } - -- (MASConstraint * (^)(MASLayoutPriority priority))priority { MASMethodNotImplemented(); } - -- (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { MASMethodNotImplemented(); } - -- (MASConstraint * (^)(id key))key { MASMethodNotImplemented(); } - -- (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); } - -- (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); } - -- (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); } - -- (void)setOffset:(CGFloat __unused)offset { MASMethodNotImplemented(); } - -#if TARGET_OS_MAC && !TARGET_OS_IPHONE - -- (MASConstraint *)animator { MASMethodNotImplemented(); } - -#endif - -- (void)activate { MASMethodNotImplemented(); } - -- (void)deactivate { MASMethodNotImplemented(); } - -- (void)install { MASMethodNotImplemented(); } - -- (void)uninstall { MASMethodNotImplemented(); } - -@end diff --git a/JCFrameLayout/Masonry/MASConstraintMaker.h b/JCFrameLayout/Masonry/MASConstraintMaker.h deleted file mode 100755 index 7e31858..0000000 --- a/JCFrameLayout/Masonry/MASConstraintMaker.h +++ /dev/null @@ -1,132 +0,0 @@ -// -// MASConstraintBuilder.h -// Masonry -// -// Created by Jonas Budelmann on 20/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "MASConstraint.h" -#import "MASUtilities.h" - -typedef NS_OPTIONS(NSInteger, MASAttribute) { - MASAttributeLeft = 1 << NSLayoutAttributeLeft, - MASAttributeRight = 1 << NSLayoutAttributeRight, - MASAttributeTop = 1 << NSLayoutAttributeTop, - MASAttributeBottom = 1 << NSLayoutAttributeBottom, - MASAttributeLeading = 1 << NSLayoutAttributeLeading, - MASAttributeTrailing = 1 << NSLayoutAttributeTrailing, - MASAttributeWidth = 1 << NSLayoutAttributeWidth, - MASAttributeHeight = 1 << NSLayoutAttributeHeight, - MASAttributeCenterX = 1 << NSLayoutAttributeCenterX, - MASAttributeCenterY = 1 << NSLayoutAttributeCenterY, - MASAttributeBaseline = 1 << NSLayoutAttributeBaseline, - -#if TARGET_OS_IPHONE - - MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin, - MASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin, - MASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin, - MASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin, - MASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin, - MASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin, - MASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins, - MASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins, - -#endif - -}; - -/** - * Provides factory methods for creating MASConstraints. - * Constraints are collected until they are ready to be installed - * - */ -@interface MASConstraintMaker : NSObject - -/** - * The following properties return a new MASViewConstraint - * with the first item set to the makers associated view and the appropriate MASViewAttribute - */ -@property (nonatomic, strong, readonly) MASConstraint *left; -@property (nonatomic, strong, readonly) MASConstraint *top; -@property (nonatomic, strong, readonly) MASConstraint *right; -@property (nonatomic, strong, readonly) MASConstraint *bottom; -@property (nonatomic, strong, readonly) MASConstraint *leading; -@property (nonatomic, strong, readonly) MASConstraint *trailing; -@property (nonatomic, strong, readonly) MASConstraint *width; -@property (nonatomic, strong, readonly) MASConstraint *height; -@property (nonatomic, strong, readonly) MASConstraint *centerX; -@property (nonatomic, strong, readonly) MASConstraint *centerY; -@property (nonatomic, strong, readonly) MASConstraint *baseline; - -#if TARGET_OS_IPHONE - -@property (nonatomic, strong, readonly) MASConstraint *leftMargin; -@property (nonatomic, strong, readonly) MASConstraint *rightMargin; -@property (nonatomic, strong, readonly) MASConstraint *topMargin; -@property (nonatomic, strong, readonly) MASConstraint *bottomMargin; -@property (nonatomic, strong, readonly) MASConstraint *leadingMargin; -@property (nonatomic, strong, readonly) MASConstraint *trailingMargin; -@property (nonatomic, strong, readonly) MASConstraint *centerXWithinMargins; -@property (nonatomic, strong, readonly) MASConstraint *centerYWithinMargins; - -#endif - -/** - * Returns a block which creates a new MASCompositeConstraint with the first item set - * to the makers associated view and children corresponding to the set bits in the - * MASAttribute parameter. Combine multiple attributes via binary-or. - */ -@property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs); - -/** - * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges - * which generates the appropriate MASViewConstraint children (top, left, bottom, right) - * with the first item set to the makers associated view - */ -@property (nonatomic, strong, readonly) MASConstraint *edges; - -/** - * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize - * which generates the appropriate MASViewConstraint children (width, height) - * with the first item set to the makers associated view - */ -@property (nonatomic, strong, readonly) MASConstraint *size; - -/** - * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter - * which generates the appropriate MASViewConstraint children (centerX, centerY) - * with the first item set to the makers associated view - */ -@property (nonatomic, strong, readonly) MASConstraint *center; - -/** - * Whether or not to check for an existing constraint instead of adding constraint - */ -@property (nonatomic, assign) BOOL updateExisting; - -/** - * Whether or not to remove existing constraints prior to installing - */ -@property (nonatomic, assign) BOOL removeExisting; - -/** - * initialises the maker with a default view - * - * @param view any MASConstrait are created with this view as the first item - * - * @return a new MASConstraintMaker - */ -- (id)initWithView:(MAS_VIEW *)view; - -/** - * Calls install method on any MASConstraints which have been created by this maker - * - * @return an array of all the installed MASConstraints - */ -- (NSArray *)install; - -- (MASConstraint * (^)(dispatch_block_t))group; - -@end diff --git a/JCFrameLayout/Masonry/MASConstraintMaker.m b/JCFrameLayout/Masonry/MASConstraintMaker.m deleted file mode 100755 index 78f93ec..0000000 --- a/JCFrameLayout/Masonry/MASConstraintMaker.m +++ /dev/null @@ -1,250 +0,0 @@ -// -// MASConstraintBuilder.m -// Masonry -// -// Created by Jonas Budelmann on 20/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "MASConstraintMaker.h" -#import "MASViewConstraint.h" -#import "MASCompositeConstraint.h" -#import "MASConstraint+Private.h" -#import "MASViewAttribute.h" -#import "View+MASAdditions.h" - -@interface MASConstraintMaker () - -@property (nonatomic, weak) MAS_VIEW *view; -@property (nonatomic, strong) NSMutableArray *constraints; - -@end - -@implementation MASConstraintMaker - -- (id)initWithView:(MAS_VIEW *)view { - self = [super init]; - if (!self) return nil; - - self.view = view; - self.constraints = NSMutableArray.new; - - return self; -} - -- (NSArray *)install { - if (self.removeExisting) { - NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.view]; - for (MASConstraint *constraint in installedConstraints) { - [constraint uninstall]; - } - } - NSArray *constraints = self.constraints.copy; - for (MASConstraint *constraint in constraints) { - constraint.updateExisting = self.updateExisting; - [constraint install]; - } - [self.constraints removeAllObjects]; - return constraints; -} - -#pragma mark - MASConstraintDelegate - -- (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint { - NSUInteger index = [self.constraints indexOfObject:constraint]; - NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint); - [self.constraints replaceObjectAtIndex:index withObject:replacementConstraint]; -} - -- (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { - MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view layoutAttribute:layoutAttribute]; - MASViewConstraint *newConstraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute]; - if ([constraint isKindOfClass:MASViewConstraint.class]) { - //replace with composite constraint - NSArray *children = @[constraint, newConstraint]; - MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children]; - compositeConstraint.delegate = self; - [self constraint:constraint shouldBeReplacedWithConstraint:compositeConstraint]; - return compositeConstraint; - } - if (!constraint) { - newConstraint.delegate = self; - [self.constraints addObject:newConstraint]; - } - return newConstraint; -} - -- (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs { - __unused MASAttribute anyAttribute = (MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading - | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX - | MASAttributeCenterY | MASAttributeBaseline -#if TARGET_OS_IPHONE - | MASAttributeLeftMargin | MASAttributeRightMargin | MASAttributeTopMargin | MASAttributeBottomMargin - | MASAttributeLeadingMargin | MASAttributeTrailingMargin | MASAttributeCenterXWithinMargins - | MASAttributeCenterYWithinMargins -#endif - ); - - NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)"); - - NSMutableArray *attributes = [NSMutableArray array]; - - if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left]; - if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right]; - if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top]; - if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom]; - if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading]; - if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing]; - if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width]; - if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height]; - if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX]; - if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY]; - if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline]; - -#if TARGET_OS_IPHONE - - if (attrs & MASAttributeLeftMargin) [attributes addObject:self.view.mas_leftMargin]; - if (attrs & MASAttributeRightMargin) [attributes addObject:self.view.mas_rightMargin]; - if (attrs & MASAttributeTopMargin) [attributes addObject:self.view.mas_topMargin]; - if (attrs & MASAttributeBottomMargin) [attributes addObject:self.view.mas_bottomMargin]; - if (attrs & MASAttributeLeadingMargin) [attributes addObject:self.view.mas_leadingMargin]; - if (attrs & MASAttributeTrailingMargin) [attributes addObject:self.view.mas_trailingMargin]; - if (attrs & MASAttributeCenterXWithinMargins) [attributes addObject:self.view.mas_centerXWithinMargins]; - if (attrs & MASAttributeCenterYWithinMargins) [attributes addObject:self.view.mas_centerYWithinMargins]; - -#endif - - NSMutableArray *children = [NSMutableArray arrayWithCapacity:attributes.count]; - - for (MASViewAttribute *a in attributes) { - [children addObject:[[MASViewConstraint alloc] initWithFirstViewAttribute:a]]; - } - - MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children]; - constraint.delegate = self; - [self.constraints addObject:constraint]; - return constraint; -} - -#pragma mark - standard Attributes - -- (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { - return [self constraint:nil addConstraintWithLayoutAttribute:layoutAttribute]; -} - -- (MASConstraint *)left { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft]; -} - -- (MASConstraint *)top { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop]; -} - -- (MASConstraint *)right { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight]; -} - -- (MASConstraint *)bottom { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom]; -} - -- (MASConstraint *)leading { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading]; -} - -- (MASConstraint *)trailing { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing]; -} - -- (MASConstraint *)width { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth]; -} - -- (MASConstraint *)height { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight]; -} - -- (MASConstraint *)centerX { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX]; -} - -- (MASConstraint *)centerY { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY]; -} - -- (MASConstraint *)baseline { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline]; -} - -- (MASConstraint *(^)(MASAttribute))attributes { - return ^(MASAttribute attrs){ - return [self addConstraintWithAttributes:attrs]; - }; -} - -#if TARGET_OS_IPHONE - -- (MASConstraint *)leftMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin]; -} - -- (MASConstraint *)rightMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin]; -} - -- (MASConstraint *)topMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin]; -} - -- (MASConstraint *)bottomMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin]; -} - -- (MASConstraint *)leadingMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin]; -} - -- (MASConstraint *)trailingMargin { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin]; -} - -- (MASConstraint *)centerXWithinMargins { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins]; -} - -- (MASConstraint *)centerYWithinMargins { - return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins]; -} - -#endif - - -#pragma mark - composite Attributes - -- (MASConstraint *)edges { - return [self addConstraintWithAttributes:MASAttributeTop | MASAttributeLeft | MASAttributeRight | MASAttributeBottom]; -} - -- (MASConstraint *)size { - return [self addConstraintWithAttributes:MASAttributeWidth | MASAttributeHeight]; -} - -- (MASConstraint *)center { - return [self addConstraintWithAttributes:MASAttributeCenterX | MASAttributeCenterY]; -} - -#pragma mark - grouping - -- (MASConstraint *(^)(dispatch_block_t group))group { - return ^id(dispatch_block_t group) { - NSInteger previousCount = self.constraints.count; - group(); - - NSArray *children = [self.constraints subarrayWithRange:NSMakeRange(previousCount, self.constraints.count - previousCount)]; - MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children]; - constraint.delegate = self; - return constraint; - }; -} - -@end diff --git a/JCFrameLayout/Masonry/MASLayoutConstraint.h b/JCFrameLayout/Masonry/MASLayoutConstraint.h deleted file mode 100755 index 699041c..0000000 --- a/JCFrameLayout/Masonry/MASLayoutConstraint.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// MASLayoutConstraint.h -// Masonry -// -// Created by Jonas Budelmann on 3/08/13. -// Copyright (c) 2013 Jonas Budelmann. All rights reserved. -// - -#import "MASUtilities.h" - -/** - * When you are debugging or printing the constraints attached to a view this subclass - * makes it easier to identify which constraints have been created via Masonry - */ -@interface MASLayoutConstraint : NSLayoutConstraint - -/** - * a key to associate with this constraint - */ -@property (nonatomic, strong) id mas_key; - -@end diff --git a/JCFrameLayout/Masonry/MASLayoutConstraint.m b/JCFrameLayout/Masonry/MASLayoutConstraint.m deleted file mode 100755 index 3483f02..0000000 --- a/JCFrameLayout/Masonry/MASLayoutConstraint.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// MASLayoutConstraint.m -// Masonry -// -// Created by Jonas Budelmann on 3/08/13. -// Copyright (c) 2013 Jonas Budelmann. All rights reserved. -// - -#import "MASLayoutConstraint.h" - -@implementation MASLayoutConstraint - -@end diff --git a/JCFrameLayout/Masonry/MASUtilities.h b/JCFrameLayout/Masonry/MASUtilities.h deleted file mode 100755 index 472d7a1..0000000 --- a/JCFrameLayout/Masonry/MASUtilities.h +++ /dev/null @@ -1,131 +0,0 @@ -// -// MASUtilities.h -// Masonry -// -// Created by Jonas Budelmann on 19/08/13. -// Copyright (c) 2013 Jonas Budelmann. All rights reserved. -// - -#import - -#if TARGET_OS_IPHONE - - #import - #define MAS_VIEW UIView - #define MASEdgeInsets UIEdgeInsets - - typedef UILayoutPriority MASLayoutPriority; - static const MASLayoutPriority MASLayoutPriorityRequired = UILayoutPriorityRequired; - static const MASLayoutPriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh; - static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 500; - static const MASLayoutPriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow; - static const MASLayoutPriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel; - -#elif TARGET_OS_MAC - - #import - #define MAS_VIEW NSView - #define MASEdgeInsets NSEdgeInsets - - typedef NSLayoutPriority MASLayoutPriority; - static const MASLayoutPriority MASLayoutPriorityRequired = NSLayoutPriorityRequired; - static const MASLayoutPriority MASLayoutPriorityDefaultHigh = NSLayoutPriorityDefaultHigh; - static const MASLayoutPriority MASLayoutPriorityDragThatCanResizeWindow = NSLayoutPriorityDragThatCanResizeWindow; - static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 501; - static const MASLayoutPriority MASLayoutPriorityWindowSizeStayPut = NSLayoutPriorityWindowSizeStayPut; - static const MASLayoutPriority MASLayoutPriorityDragThatCannotResizeWindow = NSLayoutPriorityDragThatCannotResizeWindow; - static const MASLayoutPriority MASLayoutPriorityDefaultLow = NSLayoutPriorityDefaultLow; - static const MASLayoutPriority MASLayoutPriorityFittingSizeCompression = NSLayoutPriorityFittingSizeCompression; - -#endif - -/** - * Allows you to attach keys to objects matching the variable names passed. - * - * view1.mas_key = @"view1", view2.mas_key = @"view2"; - * - * is equivalent to: - * - * MASAttachKeys(view1, view2); - */ -#define MASAttachKeys(...) \ - NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \ - for (id key in keyPairs.allKeys) { \ - id obj = keyPairs[key]; \ - NSAssert([obj respondsToSelector:@selector(setMas_key:)], \ - @"Cannot attach mas_key to %@", obj); \ - [obj setMas_key:key]; \ - } - -/** - * Used to create object hashes - * Based on http://www.mikeash.com/pyblog/friday-qa-2010-06-18-implementing-equality-and-hashing.html - */ -#define MAS_NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger)) -#define MAS_NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (MAS_NSUINT_BIT - howmuch))) - -/** - * Given a scalar or struct value, wraps it in NSValue - * Based on EXPObjectify: https://github.com/specta/expecta - */ -static inline id _MASBoxValue(const char *type, ...) { - va_list v; - va_start(v, type); - id obj = nil; - if (strcmp(type, @encode(id)) == 0) { - id actual = va_arg(v, id); - obj = actual; - } else if (strcmp(type, @encode(CGPoint)) == 0) { - CGPoint actual = (CGPoint)va_arg(v, CGPoint); - obj = [NSValue value:&actual withObjCType:type]; - } else if (strcmp(type, @encode(CGSize)) == 0) { - CGSize actual = (CGSize)va_arg(v, CGSize); - obj = [NSValue value:&actual withObjCType:type]; - } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) { - MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets); - obj = [NSValue value:&actual withObjCType:type]; - } else if (strcmp(type, @encode(double)) == 0) { - double actual = (double)va_arg(v, double); - obj = [NSNumber numberWithDouble:actual]; - } else if (strcmp(type, @encode(float)) == 0) { - float actual = (float)va_arg(v, double); - obj = [NSNumber numberWithFloat:actual]; - } else if (strcmp(type, @encode(int)) == 0) { - int actual = (int)va_arg(v, int); - obj = [NSNumber numberWithInt:actual]; - } else if (strcmp(type, @encode(long)) == 0) { - long actual = (long)va_arg(v, long); - obj = [NSNumber numberWithLong:actual]; - } else if (strcmp(type, @encode(long long)) == 0) { - long long actual = (long long)va_arg(v, long long); - obj = [NSNumber numberWithLongLong:actual]; - } else if (strcmp(type, @encode(short)) == 0) { - short actual = (short)va_arg(v, int); - obj = [NSNumber numberWithShort:actual]; - } else if (strcmp(type, @encode(char)) == 0) { - char actual = (char)va_arg(v, int); - obj = [NSNumber numberWithChar:actual]; - } else if (strcmp(type, @encode(bool)) == 0) { - bool actual = (bool)va_arg(v, int); - obj = [NSNumber numberWithBool:actual]; - } else if (strcmp(type, @encode(unsigned char)) == 0) { - unsigned char actual = (unsigned char)va_arg(v, unsigned int); - obj = [NSNumber numberWithUnsignedChar:actual]; - } else if (strcmp(type, @encode(unsigned int)) == 0) { - unsigned int actual = (unsigned int)va_arg(v, unsigned int); - obj = [NSNumber numberWithUnsignedInt:actual]; - } else if (strcmp(type, @encode(unsigned long)) == 0) { - unsigned long actual = (unsigned long)va_arg(v, unsigned long); - obj = [NSNumber numberWithUnsignedLong:actual]; - } else if (strcmp(type, @encode(unsigned long long)) == 0) { - unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long); - obj = [NSNumber numberWithUnsignedLongLong:actual]; - } else if (strcmp(type, @encode(unsigned short)) == 0) { - unsigned short actual = (unsigned short)va_arg(v, unsigned int); - obj = [NSNumber numberWithUnsignedShort:actual]; - } - va_end(v); - return obj; -} - -#define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value)) diff --git a/JCFrameLayout/Masonry/MASViewAttribute.h b/JCFrameLayout/Masonry/MASViewAttribute.h deleted file mode 100755 index f594f48..0000000 --- a/JCFrameLayout/Masonry/MASViewAttribute.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// MASAttribute.h -// Masonry -// -// Created by Jonas Budelmann on 21/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "MASUtilities.h" - -/** - * An immutable tuple which stores the view and the related NSLayoutAttribute. - * Describes part of either the left or right hand side of a constraint equation - */ -@interface MASViewAttribute : NSObject - -/** - * The view which the reciever relates to - */ -@property (nonatomic, weak, readonly) MAS_VIEW *view; - -/** - * The attribute which the reciever relates to - */ -@property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute; - -/** - * The designated initializer. - */ -- (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute; - -/** - * Determine whether the layoutAttribute is a size attribute - * - * @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight - */ -- (BOOL)isSizeAttribute; - -@end diff --git a/JCFrameLayout/Masonry/MASViewAttribute.m b/JCFrameLayout/Masonry/MASViewAttribute.m deleted file mode 100755 index 1032826..0000000 --- a/JCFrameLayout/Masonry/MASViewAttribute.m +++ /dev/null @@ -1,40 +0,0 @@ -// -// MASAttribute.m -// Masonry -// -// Created by Jonas Budelmann on 21/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "MASViewAttribute.h" - -@implementation MASViewAttribute - -- (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute { - self = [super init]; - if (!self) return nil; - - _view = view; - _layoutAttribute = layoutAttribute; - - return self; -} - -- (BOOL)isSizeAttribute { - return self.layoutAttribute == NSLayoutAttributeWidth - || self.layoutAttribute == NSLayoutAttributeHeight; -} - -- (BOOL)isEqual:(MASViewAttribute *)viewAttribute { - if ([viewAttribute isKindOfClass:self.class]) { - return self.view == viewAttribute.view - && self.layoutAttribute == viewAttribute.layoutAttribute; - } - return [super isEqual:viewAttribute]; -} - -- (NSUInteger)hash { - return MAS_NSUINTROTATE([self.view hash], MAS_NSUINT_BIT / 2) ^ self.layoutAttribute; -} - -@end diff --git a/JCFrameLayout/Masonry/MASViewConstraint.h b/JCFrameLayout/Masonry/MASViewConstraint.h deleted file mode 100755 index 5c78f7a..0000000 --- a/JCFrameLayout/Masonry/MASViewConstraint.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// MASConstraint.h -// Masonry -// -// Created by Jonas Budelmann on 20/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "MASViewAttribute.h" -#import "MASConstraint.h" -#import "MASLayoutConstraint.h" -#import "MASUtilities.h" - -/** - * A single constraint. - * Contains the attributes neccessary for creating a NSLayoutConstraint and adding it to the appropriate view - */ -@interface MASViewConstraint : MASConstraint - -/** - * First item/view and first attribute of the NSLayoutConstraint - */ -@property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute; - -/** - * Second item/view and second attribute of the NSLayoutConstraint - */ -@property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute; - -/** - * initialises the MASViewConstraint with the first part of the equation - * - * @param firstViewAttribute view.mas_left, view.mas_width etc. - * - * @return a new view constraint - */ -- (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute; - -/** - * Returns all MASViewConstraints installed with this view as a first item. - * - * @param view A view to retrieve constraints for. - * - * @return An array of MASViewConstraints. - */ -+ (NSArray *)installedConstraintsForView:(MAS_VIEW *)view; - -@end diff --git a/JCFrameLayout/Masonry/MASViewConstraint.m b/JCFrameLayout/Masonry/MASViewConstraint.m deleted file mode 100755 index 8e3d2d6..0000000 --- a/JCFrameLayout/Masonry/MASViewConstraint.m +++ /dev/null @@ -1,396 +0,0 @@ -// -// MASConstraint.m -// Masonry -// -// Created by Jonas Budelmann on 20/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "MASViewConstraint.h" -#import "MASConstraint+Private.h" -#import "MASCompositeConstraint.h" -#import "MASLayoutConstraint.h" -#import "View+MASAdditions.h" -#import - -@interface MAS_VIEW (MASConstraints) - -@property (nonatomic, readonly) NSMutableSet *mas_installedConstraints; - -@end - -@implementation MAS_VIEW (MASConstraints) - -static char kInstalledConstraintsKey; - -- (NSMutableSet *)mas_installedConstraints { - NSMutableSet *constraints = objc_getAssociatedObject(self, &kInstalledConstraintsKey); - if (!constraints) { - constraints = [NSMutableSet set]; - objc_setAssociatedObject(self, &kInstalledConstraintsKey, constraints, OBJC_ASSOCIATION_RETAIN_NONATOMIC); - } - return constraints; -} - -@end - - -@interface MASViewConstraint () - -@property (nonatomic, strong, readwrite) MASViewAttribute *secondViewAttribute; -@property (nonatomic, weak) MAS_VIEW *installedView; -@property (nonatomic, weak) MASLayoutConstraint *layoutConstraint; -@property (nonatomic, assign) NSLayoutRelation layoutRelation; -@property (nonatomic, assign) MASLayoutPriority layoutPriority; -@property (nonatomic, assign) CGFloat layoutMultiplier; -@property (nonatomic, assign) CGFloat layoutConstant; -@property (nonatomic, assign) BOOL hasLayoutRelation; -@property (nonatomic, strong) id mas_key; -@property (nonatomic, assign) BOOL useAnimator; - -@end - -@implementation MASViewConstraint - -- (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute { - self = [super init]; - if (!self) return nil; - - _firstViewAttribute = firstViewAttribute; - self.layoutPriority = MASLayoutPriorityRequired; - self.layoutMultiplier = 1; - - return self; -} - -#pragma mark - NSCoping - -- (id)copyWithZone:(NSZone __unused *)zone { - MASViewConstraint *constraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:self.firstViewAttribute]; - constraint.layoutConstant = self.layoutConstant; - constraint.layoutRelation = self.layoutRelation; - constraint.layoutPriority = self.layoutPriority; - constraint.layoutMultiplier = self.layoutMultiplier; - constraint.delegate = self.delegate; - return constraint; -} - -#pragma mark - Public - -+ (NSArray *)installedConstraintsForView:(MAS_VIEW *)view { - return [view.mas_installedConstraints allObjects]; -} - -#pragma mark - Private - -- (void)setLayoutConstant:(CGFloat)layoutConstant { - _layoutConstant = layoutConstant; - -#if TARGET_OS_MAC && !TARGET_OS_IPHONE - if (self.useAnimator) { - [self.layoutConstraint.animator setConstant:layoutConstant]; - } else { - self.layoutConstraint.constant = layoutConstant; - } -#else - self.layoutConstraint.constant = layoutConstant; -#endif -} - -- (void)setLayoutRelation:(NSLayoutRelation)layoutRelation { - _layoutRelation = layoutRelation; - self.hasLayoutRelation = YES; -} - -- (BOOL)supportsActiveProperty { - return [self.layoutConstraint respondsToSelector:@selector(isActive)]; -} - -- (BOOL)isActive { - BOOL active = YES; - if ([self supportsActiveProperty]) { - active = [self.layoutConstraint isActive]; - } - - return active; -} - -- (BOOL)hasBeenInstalled { - return (self.layoutConstraint != nil) && [self isActive]; -} - -- (void)setSecondViewAttribute:(id)secondViewAttribute { - if ([secondViewAttribute isKindOfClass:NSValue.class]) { - [self setLayoutConstantWithValue:secondViewAttribute]; - } else if ([secondViewAttribute isKindOfClass:MAS_VIEW.class]) { - _secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute]; - } else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) { - _secondViewAttribute = secondViewAttribute; - } else { - NSAssert(NO, @"attempting to add unsupported attribute: %@", secondViewAttribute); - } -} - -#pragma mark - NSLayoutConstraint multiplier proxies - -- (MASConstraint * (^)(CGFloat))multipliedBy { - return ^id(CGFloat multiplier) { - NSAssert(!self.hasBeenInstalled, - @"Cannot modify constraint multiplier after it has been installed"); - - self.layoutMultiplier = multiplier; - return self; - }; -} - - -- (MASConstraint * (^)(CGFloat))dividedBy { - return ^id(CGFloat divider) { - NSAssert(!self.hasBeenInstalled, - @"Cannot modify constraint multiplier after it has been installed"); - - self.layoutMultiplier = 1.0/divider; - return self; - }; -} - -#pragma mark - MASLayoutPriority proxy - -- (MASConstraint * (^)(MASLayoutPriority))priority { - return ^id(MASLayoutPriority priority) { - NSAssert(!self.hasBeenInstalled, - @"Cannot modify constraint priority after it has been installed"); - - self.layoutPriority = priority; - return self; - }; -} - -#pragma mark - NSLayoutRelation proxy - -- (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { - return ^id(id attribute, NSLayoutRelation relation) { - if ([attribute isKindOfClass:NSArray.class]) { - NSAssert(!self.hasLayoutRelation, @"Redefinition of constraint relation"); - NSMutableArray *children = NSMutableArray.new; - for (id attr in attribute) { - MASViewConstraint *viewConstraint = [self copy]; - viewConstraint.secondViewAttribute = attr; - [children addObject:viewConstraint]; - } - MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children]; - compositeConstraint.delegate = self.delegate; - [self.delegate constraint:self shouldBeReplacedWithConstraint:compositeConstraint]; - return compositeConstraint; - } else { - NSAssert(!self.hasLayoutRelation || self.layoutRelation == relation && [attribute isKindOfClass:NSValue.class], @"Redefinition of constraint relation"); - self.layoutRelation = relation; - self.secondViewAttribute = attribute; - return self; - } - }; -} - -#pragma mark - Semantic properties - -- (MASConstraint *)with { - return self; -} - -- (MASConstraint *)and { - return self; -} - -#pragma mark - attribute chaining - -- (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute { - NSAssert(!self.hasLayoutRelation, @"Attributes should be chained before defining the constraint relation"); - - return [self.delegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute]; -} - -#pragma mark - Animator proxy - -#if TARGET_OS_MAC && !TARGET_OS_IPHONE - -- (MASConstraint *)animator { - self.useAnimator = YES; - return self; -} - -#endif - -#pragma mark - debug helpers - -- (MASConstraint * (^)(id))key { - return ^id(id key) { - self.mas_key = key; - return self; - }; -} - -#pragma mark - NSLayoutConstraint constant setters - -- (void)setInsets:(MASEdgeInsets)insets { - NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute; - switch (layoutAttribute) { - case NSLayoutAttributeLeft: - case NSLayoutAttributeLeading: - self.layoutConstant = insets.left; - break; - case NSLayoutAttributeTop: - self.layoutConstant = insets.top; - break; - case NSLayoutAttributeBottom: - self.layoutConstant = -insets.bottom; - break; - case NSLayoutAttributeRight: - case NSLayoutAttributeTrailing: - self.layoutConstant = -insets.right; - break; - default: - break; - } -} - -- (void)setOffset:(CGFloat)offset { - self.layoutConstant = offset; -} - -- (void)setSizeOffset:(CGSize)sizeOffset { - NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute; - switch (layoutAttribute) { - case NSLayoutAttributeWidth: - self.layoutConstant = sizeOffset.width; - break; - case NSLayoutAttributeHeight: - self.layoutConstant = sizeOffset.height; - break; - default: - break; - } -} - -- (void)setCenterOffset:(CGPoint)centerOffset { - NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute; - switch (layoutAttribute) { - case NSLayoutAttributeCenterX: - self.layoutConstant = centerOffset.x; - break; - case NSLayoutAttributeCenterY: - self.layoutConstant = centerOffset.y; - break; - default: - break; - } -} - -#pragma mark - MASConstraint - -- (void)activate { - if ([self supportsActiveProperty] && self.layoutConstraint) { - if (self.hasBeenInstalled) { - return; - } - self.layoutConstraint.active = YES; - [self.firstViewAttribute.view.mas_installedConstraints addObject:self]; - } else { - [self install]; - } -} - -- (void)deactivate { - if ([self supportsActiveProperty]) { - self.layoutConstraint.active = NO; - [self.firstViewAttribute.view.mas_installedConstraints removeObject:self]; - } else { - [self uninstall]; - } -} - -- (void)install { - if (self.hasBeenInstalled) { - return; - } - - MAS_VIEW *firstLayoutItem = self.firstViewAttribute.view; - - NSLayoutAttribute firstLayoutAttribute = self.firstViewAttribute.layoutAttribute; - MAS_VIEW *secondLayoutItem = self.secondViewAttribute.view; - NSLayoutAttribute secondLayoutAttribute = self.secondViewAttribute.layoutAttribute; - - // alignment attributes must have a secondViewAttribute - // therefore we assume that is refering to superview - // eg make.left.equalTo(@10) - if (!self.firstViewAttribute.isSizeAttribute && !self.secondViewAttribute) { - secondLayoutItem = firstLayoutItem.superview; - secondLayoutAttribute = firstLayoutAttribute; - } - - MASLayoutConstraint *layoutConstraint - = [MASLayoutConstraint constraintWithItem:firstLayoutItem - attribute:firstLayoutAttribute - relatedBy:self.layoutRelation - toItem:secondLayoutItem - attribute:secondLayoutAttribute - multiplier:self.layoutMultiplier - constant:self.layoutConstant]; - - layoutConstraint.priority = self.layoutPriority; - layoutConstraint.mas_key = self.mas_key; - - if (secondLayoutItem) { - MAS_VIEW *closestCommonSuperview = [firstLayoutItem mas_closestCommonSuperview:secondLayoutItem]; - NSAssert(closestCommonSuperview, - @"couldn't find a common superview for %@ and %@", - firstLayoutItem, secondLayoutItem); - self.installedView = closestCommonSuperview; - } else { - self.installedView = firstLayoutItem; - } - - - MASLayoutConstraint *existingConstraint = nil; - if (self.updateExisting) { - existingConstraint = [self layoutConstraintSimilarTo:layoutConstraint]; - } - if (existingConstraint) { - // just update the constant - existingConstraint.constant = layoutConstraint.constant; - self.layoutConstraint = existingConstraint; - } else { - [self.installedView addConstraint:layoutConstraint]; - self.layoutConstraint = layoutConstraint; - [firstLayoutItem.mas_installedConstraints addObject:self]; - } -} - -- (MASLayoutConstraint *)layoutConstraintSimilarTo:(MASLayoutConstraint *)layoutConstraint { - // check if any constraints are the same apart from the only mutable property constant - - // go through constraints in reverse as we do not want to match auto-resizing or interface builder constraints - // and they are likely to be added first. - for (NSLayoutConstraint *existingConstraint in self.installedView.constraints.reverseObjectEnumerator) { - if (![existingConstraint isKindOfClass:MASLayoutConstraint.class]) continue; - if (existingConstraint.firstItem != layoutConstraint.firstItem) continue; - if (existingConstraint.secondItem != layoutConstraint.secondItem) continue; - if (existingConstraint.firstAttribute != layoutConstraint.firstAttribute) continue; - if (existingConstraint.secondAttribute != layoutConstraint.secondAttribute) continue; - if (existingConstraint.relation != layoutConstraint.relation) continue; - if (existingConstraint.multiplier != layoutConstraint.multiplier) continue; - if (existingConstraint.priority != layoutConstraint.priority) continue; - - return (id)existingConstraint; - } - return nil; -} - -- (void)uninstall { - [self.installedView removeConstraint:self.layoutConstraint]; - self.layoutConstraint = nil; - self.installedView = nil; - - [self.firstViewAttribute.view.mas_installedConstraints removeObject:self]; -} - -@end diff --git a/JCFrameLayout/Masonry/Masonry.h b/JCFrameLayout/Masonry/Masonry.h deleted file mode 100755 index 168811a..0000000 --- a/JCFrameLayout/Masonry/Masonry.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// Masonry.h -// Masonry -// -// Created by Jonas Budelmann on 20/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import - -//! Project version number for Masonry. -FOUNDATION_EXPORT double MasonryVersionNumber; - -//! Project version string for Masonry. -FOUNDATION_EXPORT const unsigned char MasonryVersionString[]; - -#import "MASUtilities.h" -#import "View+MASAdditions.h" -#import "View+MASShorthandAdditions.h" -#import "NSArray+MASAdditions.h" -#import "NSArray+MASShorthandAdditions.h" -#import "MASConstraint.h" -#import "MASCompositeConstraint.h" -#import "MASViewAttribute.h" -#import "MASViewConstraint.h" -#import "MASConstraintMaker.h" -#import "MASLayoutConstraint.h" -#import "NSLayoutConstraint+MASDebugAdditions.h" diff --git a/JCFrameLayout/Masonry/NSArray+MASAdditions.h b/JCFrameLayout/Masonry/NSArray+MASAdditions.h deleted file mode 100755 index 189d51f..0000000 --- a/JCFrameLayout/Masonry/NSArray+MASAdditions.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// NSArray+MASAdditions.h -// -// -// Created by Daniel Hammond on 11/26/13. -// -// - -#import "MASUtilities.h" -#import "MASConstraintMaker.h" -#import "MASViewAttribute.h" - -@interface NSArray (MASAdditions) - -/** - * Creates a MASConstraintMaker with each view in the callee. - * Any constraints defined are added to the view or the appropriate superview once the block has finished executing on each view - * - * @param block scope within which you can build up the constraints which you wish to apply to each view. - * - * @return Array of created MASConstraints - */ -- (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block; - -/** - * Creates a MASConstraintMaker with each view in the callee. - * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view. - * If an existing constraint exists then it will be updated instead. - * - * @param block scope within which you can build up the constraints which you wish to apply to each view. - * - * @return Array of created/updated MASConstraints - */ -- (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block; - -/** - * Creates a MASConstraintMaker with each view in the callee. - * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view. - * All constraints previously installed for the views will be removed. - * - * @param block scope within which you can build up the constraints which you wish to apply to each view. - * - * @return Array of created/updated MASConstraints - */ -- (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block; - -@end diff --git a/JCFrameLayout/Masonry/NSArray+MASAdditions.m b/JCFrameLayout/Masonry/NSArray+MASAdditions.m deleted file mode 100755 index dbbe671..0000000 --- a/JCFrameLayout/Masonry/NSArray+MASAdditions.m +++ /dev/null @@ -1,41 +0,0 @@ -// -// NSArray+MASAdditions.m -// -// -// Created by Daniel Hammond on 11/26/13. -// -// - -#import "NSArray+MASAdditions.h" -#import "View+MASAdditions.h" - -@implementation NSArray (MASAdditions) - -- (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block { - NSMutableArray *constraints = [NSMutableArray array]; - for (MAS_VIEW *view in self) { - NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); - [constraints addObjectsFromArray:[view mas_makeConstraints:block]]; - } - return constraints; -} - -- (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block { - NSMutableArray *constraints = [NSMutableArray array]; - for (MAS_VIEW *view in self) { - NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); - [constraints addObjectsFromArray:[view mas_updateConstraints:block]]; - } - return constraints; -} - -- (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { - NSMutableArray *constraints = [NSMutableArray array]; - for (MAS_VIEW *view in self) { - NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views"); - [constraints addObjectsFromArray:[view mas_remakeConstraints:block]]; - } - return constraints; -} - -@end diff --git a/JCFrameLayout/Masonry/NSArray+MASShorthandAdditions.h b/JCFrameLayout/Masonry/NSArray+MASShorthandAdditions.h deleted file mode 100755 index 8b47369..0000000 --- a/JCFrameLayout/Masonry/NSArray+MASShorthandAdditions.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// NSArray+MASShorthandAdditions.h -// Masonry -// -// Created by Jonas Budelmann on 22/07/13. -// Copyright (c) 2013 Jonas Budelmann. All rights reserved. -// - -#import "NSArray+MASAdditions.h" - -#ifdef MAS_SHORTHAND - -/** - * Shorthand array additions without the 'mas_' prefixes, - * only enabled if MAS_SHORTHAND is defined - */ -@interface NSArray (MASShorthandAdditions) - -- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; -- (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; -- (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; - -@end - -@implementation NSArray (MASShorthandAdditions) - -- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { - return [self mas_makeConstraints:block]; -} - -- (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { - return [self mas_updateConstraints:block]; -} - -- (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { - return [self mas_remakeConstraints:block]; -} - -@end - -#endif diff --git a/JCFrameLayout/Masonry/NSLayoutConstraint+MASDebugAdditions.h b/JCFrameLayout/Masonry/NSLayoutConstraint+MASDebugAdditions.h deleted file mode 100755 index 1279b4f..0000000 --- a/JCFrameLayout/Masonry/NSLayoutConstraint+MASDebugAdditions.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// NSLayoutConstraint+MASDebugAdditions.h -// Masonry -// -// Created by Jonas Budelmann on 3/08/13. -// Copyright (c) 2013 Jonas Budelmann. All rights reserved. -// - -#import "MASUtilities.h" - -/** - * makes debug and log output of NSLayoutConstraints more readable - */ -@interface NSLayoutConstraint (MASDebugAdditions) - -@end diff --git a/JCFrameLayout/Masonry/NSLayoutConstraint+MASDebugAdditions.m b/JCFrameLayout/Masonry/NSLayoutConstraint+MASDebugAdditions.m deleted file mode 100755 index 3d10ac2..0000000 --- a/JCFrameLayout/Masonry/NSLayoutConstraint+MASDebugAdditions.m +++ /dev/null @@ -1,141 +0,0 @@ -// -// NSLayoutConstraint+MASDebugAdditions.m -// Masonry -// -// Created by Jonas Budelmann on 3/08/13. -// Copyright (c) 2013 Jonas Budelmann. All rights reserved. -// - -#import "NSLayoutConstraint+MASDebugAdditions.h" -#import "MASConstraint.h" -#import "MASLayoutConstraint.h" - -@implementation NSLayoutConstraint (MASDebugAdditions) - -#pragma mark - description maps - -+ (NSDictionary *)layoutRelationDescriptionsByValue { - static dispatch_once_t once; - static NSDictionary *descriptionMap; - dispatch_once(&once, ^{ - descriptionMap = @{ - @(NSLayoutRelationEqual) : @"==", - @(NSLayoutRelationGreaterThanOrEqual) : @">=", - @(NSLayoutRelationLessThanOrEqual) : @"<=", - }; - }); - return descriptionMap; -} - -+ (NSDictionary *)layoutAttributeDescriptionsByValue { - static dispatch_once_t once; - static NSDictionary *descriptionMap; - dispatch_once(&once, ^{ - descriptionMap = @{ - @(NSLayoutAttributeTop) : @"top", - @(NSLayoutAttributeLeft) : @"left", - @(NSLayoutAttributeBottom) : @"bottom", - @(NSLayoutAttributeRight) : @"right", - @(NSLayoutAttributeLeading) : @"leading", - @(NSLayoutAttributeTrailing) : @"trailing", - @(NSLayoutAttributeWidth) : @"width", - @(NSLayoutAttributeHeight) : @"height", - @(NSLayoutAttributeCenterX) : @"centerX", - @(NSLayoutAttributeCenterY) : @"centerY", - @(NSLayoutAttributeBaseline) : @"baseline", - -#if TARGET_OS_IPHONE - @(NSLayoutAttributeLeftMargin) : @"leftMargin", - @(NSLayoutAttributeRightMargin) : @"rightMargin", - @(NSLayoutAttributeTopMargin) : @"topMargin", - @(NSLayoutAttributeBottomMargin) : @"bottomMargin", - @(NSLayoutAttributeLeadingMargin) : @"leadingMargin", - @(NSLayoutAttributeTrailingMargin) : @"trailingMargin", - @(NSLayoutAttributeCenterXWithinMargins) : @"centerXWithinMargins", - @(NSLayoutAttributeCenterYWithinMargins) : @"centerYWithinMargins", -#endif - - }; - - }); - return descriptionMap; -} - - -+ (NSDictionary *)layoutPriorityDescriptionsByValue { - static dispatch_once_t once; - static NSDictionary *descriptionMap; - dispatch_once(&once, ^{ -#if TARGET_OS_IPHONE - descriptionMap = @{ - @(MASLayoutPriorityDefaultHigh) : @"high", - @(MASLayoutPriorityDefaultLow) : @"low", - @(MASLayoutPriorityDefaultMedium) : @"medium", - @(MASLayoutPriorityRequired) : @"required", - @(MASLayoutPriorityFittingSizeLevel) : @"fitting size", - }; -#elif TARGET_OS_MAC - descriptionMap = @{ - @(MASLayoutPriorityDefaultHigh) : @"high", - @(MASLayoutPriorityDragThatCanResizeWindow) : @"drag can resize window", - @(MASLayoutPriorityDefaultMedium) : @"medium", - @(MASLayoutPriorityWindowSizeStayPut) : @"window size stay put", - @(MASLayoutPriorityDragThatCannotResizeWindow) : @"drag cannot resize window", - @(MASLayoutPriorityDefaultLow) : @"low", - @(MASLayoutPriorityFittingSizeCompression) : @"fitting size", - @(MASLayoutPriorityRequired) : @"required", - }; -#endif - }); - return descriptionMap; -} - -#pragma mark - description override - -+ (NSString *)descriptionForObject:(id)obj { - if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) { - return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]]; - } - return [NSString stringWithFormat:@"%@:%p", [obj class], obj]; -} - -- (NSString *)description { - NSMutableString *description = [[NSMutableString alloc] initWithString:@"<"]; - - [description appendString:[self.class descriptionForObject:self]]; - - [description appendFormat:@" %@", [self.class descriptionForObject:self.firstItem]]; - if (self.firstAttribute != NSLayoutAttributeNotAnAttribute) { - [description appendFormat:@".%@", [self.class.layoutAttributeDescriptionsByValue objectForKey:@(self.firstAttribute)]]; - } - - [description appendFormat:@" %@", [self.class.layoutRelationDescriptionsByValue objectForKey:@(self.relation)]]; - - if (self.secondItem) { - [description appendFormat:@" %@", [self.class descriptionForObject:self.secondItem]]; - } - if (self.secondAttribute != NSLayoutAttributeNotAnAttribute) { - [description appendFormat:@".%@", [self.class.layoutAttributeDescriptionsByValue objectForKey:@(self.secondAttribute)]]; - } - - if (self.multiplier != 1) { - [description appendFormat:@" * %g", self.multiplier]; - } - - if (self.secondAttribute == NSLayoutAttributeNotAnAttribute) { - [description appendFormat:@" %g", self.constant]; - } else { - if (self.constant) { - [description appendFormat:@" %@ %g", (self.constant < 0 ? @"-" : @"+"), ABS(self.constant)]; - } - } - - if (self.priority != MASLayoutPriorityRequired) { - [description appendFormat:@" ^%@", [self.class.layoutPriorityDescriptionsByValue objectForKey:@(self.priority)] ?: [NSNumber numberWithDouble:self.priority]]; - } - - [description appendString:@">"]; - return description; -} - -@end diff --git a/JCFrameLayout/Masonry/View+MASAdditions.h b/JCFrameLayout/Masonry/View+MASAdditions.h deleted file mode 100755 index 94e3050..0000000 --- a/JCFrameLayout/Masonry/View+MASAdditions.h +++ /dev/null @@ -1,94 +0,0 @@ -// -// UIView+MASAdditions.h -// Masonry -// -// Created by Jonas Budelmann on 20/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "MASUtilities.h" -#import "MASConstraintMaker.h" -#import "MASViewAttribute.h" - -/** - * Provides constraint maker block - * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs - */ -@interface MAS_VIEW (MASAdditions) - -/** - * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute - */ -@property (nonatomic, strong, readonly) MASViewAttribute *mas_left; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_top; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_right; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_leading; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_width; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_height; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline; -@property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr); - -#if TARGET_OS_IPHONE - -@property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_rightMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_topMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_leadingMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_trailingMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins; -@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins; - -#endif - -/** - * a key to associate with this view - */ -@property (nonatomic, strong) id mas_key; - -/** - * Finds the closest common superview between this view and another view - * - * @param view other view - * - * @return returns nil if common superview could not be found - */ -- (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view; - -/** - * Creates a MASConstraintMaker with the callee view. - * Any constraints defined are added to the view or the appropriate superview once the block has finished executing - * - * @param block scope within which you can build up the constraints which you wish to apply to the view. - * - * @return Array of created MASConstraints - */ -- (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block; - -/** - * Creates a MASConstraintMaker with the callee view. - * Any constraints defined are added to the view or the appropriate superview once the block has finished executing. - * If an existing constraint exists then it will be updated instead. - * - * @param block scope within which you can build up the constraints which you wish to apply to the view. - * - * @return Array of created/updated MASConstraints - */ -- (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block; - -/** - * Creates a MASConstraintMaker with the callee view. - * Any constraints defined are added to the view or the appropriate superview once the block has finished executing. - * All constraints previously installed for the view will be removed. - * - * @param block scope within which you can build up the constraints which you wish to apply to the view. - * - * @return Array of created/updated MASConstraints - */ -- (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block; - -@end diff --git a/JCFrameLayout/Masonry/View+MASAdditions.m b/JCFrameLayout/Masonry/View+MASAdditions.m deleted file mode 100755 index acfaa52..0000000 --- a/JCFrameLayout/Masonry/View+MASAdditions.m +++ /dev/null @@ -1,155 +0,0 @@ -// -// UIView+MASAdditions.m -// Masonry -// -// Created by Jonas Budelmann on 20/07/13. -// Copyright (c) 2013 cloudling. All rights reserved. -// - -#import "View+MASAdditions.h" -#import - -@implementation MAS_VIEW (MASAdditions) - -- (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block { - self.translatesAutoresizingMaskIntoConstraints = NO; - MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; - block(constraintMaker); - return [constraintMaker install]; -} - -- (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block { - self.translatesAutoresizingMaskIntoConstraints = NO; - MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; - constraintMaker.updateExisting = YES; - block(constraintMaker); - return [constraintMaker install]; -} - -- (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block { - self.translatesAutoresizingMaskIntoConstraints = NO; - MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self]; - constraintMaker.removeExisting = YES; - block(constraintMaker); - return [constraintMaker install]; -} - -#pragma mark - NSLayoutAttribute properties - -- (MASViewAttribute *)mas_left { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeft]; -} - -- (MASViewAttribute *)mas_top { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTop]; -} - -- (MASViewAttribute *)mas_right { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRight]; -} - -- (MASViewAttribute *)mas_bottom { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom]; -} - -- (MASViewAttribute *)mas_leading { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeading]; -} - -- (MASViewAttribute *)mas_trailing { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailing]; -} - -- (MASViewAttribute *)mas_width { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeWidth]; -} - -- (MASViewAttribute *)mas_height { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeHeight]; -} - -- (MASViewAttribute *)mas_centerX { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterX]; -} - -- (MASViewAttribute *)mas_centerY { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterY]; -} - -- (MASViewAttribute *)mas_baseline { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline]; -} - -- (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute -{ - return ^(NSLayoutAttribute attr) { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr]; - }; -} - -#if TARGET_OS_IPHONE - -- (MASViewAttribute *)mas_leftMargin { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeftMargin]; -} - -- (MASViewAttribute *)mas_rightMargin { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRightMargin]; -} - -- (MASViewAttribute *)mas_topMargin { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTopMargin]; -} - -- (MASViewAttribute *)mas_bottomMargin { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottomMargin]; -} - -- (MASViewAttribute *)mas_leadingMargin { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeadingMargin]; -} - -- (MASViewAttribute *)mas_trailingMargin { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailingMargin]; -} - -- (MASViewAttribute *)mas_centerXWithinMargins { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterXWithinMargins]; -} - -- (MASViewAttribute *)mas_centerYWithinMargins { - return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterYWithinMargins]; -} - -#endif - -#pragma mark - associated properties - -- (id)mas_key { - return objc_getAssociatedObject(self, @selector(mas_key)); -} - -- (void)setMas_key:(id)key { - objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -#pragma mark - heirachy - -- (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view { - MAS_VIEW *closestCommonSuperview = nil; - - MAS_VIEW *secondViewSuperview = view; - while (!closestCommonSuperview && secondViewSuperview) { - MAS_VIEW *firstViewSuperview = self; - while (!closestCommonSuperview && firstViewSuperview) { - if (secondViewSuperview == firstViewSuperview) { - closestCommonSuperview = secondViewSuperview; - } - firstViewSuperview = firstViewSuperview.superview; - } - secondViewSuperview = secondViewSuperview.superview; - } - return closestCommonSuperview; -} - -@end diff --git a/JCFrameLayout/Masonry/View+MASShorthandAdditions.h b/JCFrameLayout/Masonry/View+MASShorthandAdditions.h deleted file mode 100755 index 5553912..0000000 --- a/JCFrameLayout/Masonry/View+MASShorthandAdditions.h +++ /dev/null @@ -1,101 +0,0 @@ -// -// UIView+MASShorthandAdditions.h -// Masonry -// -// Created by Jonas Budelmann on 22/07/13. -// Copyright (c) 2013 Jonas Budelmann. All rights reserved. -// - -#import "View+MASAdditions.h" - -#ifdef MAS_SHORTHAND - -/** - * Shorthand view additions without the 'mas_' prefixes, - * only enabled if MAS_SHORTHAND is defined - */ -@interface MAS_VIEW (MASShorthandAdditions) - -@property (nonatomic, strong, readonly) MASViewAttribute *left; -@property (nonatomic, strong, readonly) MASViewAttribute *top; -@property (nonatomic, strong, readonly) MASViewAttribute *right; -@property (nonatomic, strong, readonly) MASViewAttribute *bottom; -@property (nonatomic, strong, readonly) MASViewAttribute *leading; -@property (nonatomic, strong, readonly) MASViewAttribute *trailing; -@property (nonatomic, strong, readonly) MASViewAttribute *width; -@property (nonatomic, strong, readonly) MASViewAttribute *height; -@property (nonatomic, strong, readonly) MASViewAttribute *centerX; -@property (nonatomic, strong, readonly) MASViewAttribute *centerY; -@property (nonatomic, strong, readonly) MASViewAttribute *baseline; -@property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr); - -#if TARGET_OS_IPHONE - -@property (nonatomic, strong, readonly) MASViewAttribute *leftMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *rightMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *topMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin; -@property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins; -@property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins; - -#endif - -- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block; -- (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block; -- (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block; - -@end - -#define MAS_ATTR_FORWARD(attr) \ -- (MASViewAttribute *)attr { \ - return [self mas_##attr]; \ -} - -@implementation MAS_VIEW (MASShorthandAdditions) - -MAS_ATTR_FORWARD(top); -MAS_ATTR_FORWARD(left); -MAS_ATTR_FORWARD(bottom); -MAS_ATTR_FORWARD(right); -MAS_ATTR_FORWARD(leading); -MAS_ATTR_FORWARD(trailing); -MAS_ATTR_FORWARD(width); -MAS_ATTR_FORWARD(height); -MAS_ATTR_FORWARD(centerX); -MAS_ATTR_FORWARD(centerY); -MAS_ATTR_FORWARD(baseline); - -#if TARGET_OS_IPHONE - -MAS_ATTR_FORWARD(leftMargin); -MAS_ATTR_FORWARD(rightMargin); -MAS_ATTR_FORWARD(topMargin); -MAS_ATTR_FORWARD(bottomMargin); -MAS_ATTR_FORWARD(leadingMargin); -MAS_ATTR_FORWARD(trailingMargin); -MAS_ATTR_FORWARD(centerXWithinMargins); -MAS_ATTR_FORWARD(centerYWithinMargins); - -#endif - -- (MASViewAttribute *(^)(NSLayoutAttribute))attribute { - return [self mas_attribute]; -} - -- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block { - return [self mas_makeConstraints:block]; -} - -- (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block { - return [self mas_updateConstraints:block]; -} - -- (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block { - return [self mas_remakeConstraints:block]; -} - -@end - -#endif diff --git a/JCFrameLayout/QQ20170331-173628.png b/JCFrameLayout/QQ20170331-173628.png new file mode 100644 index 0000000..b5d476c Binary files /dev/null and b/JCFrameLayout/QQ20170331-173628.png differ diff --git a/JCFrameLayout/SecondViewController.m b/JCFrameLayout/SecondViewController.m deleted file mode 100644 index f111a9f..0000000 --- a/JCFrameLayout/SecondViewController.m +++ /dev/null @@ -1,201 +0,0 @@ -// -// SecondViewController.m -// JCFrameLayout -// -// Created by abc on 17/3/27. -// Copyright © 2017年 jackcat. All rights reserved. -// - -#import "SecondViewController.h" - - -#import "JCFrameLayout.h" - - -@interface SecondViewController () -/** - * <#注释#> - **/ -@property (nonatomic,strong) UIView *redView; - -/** - * <#注释#> - **/ -@property (nonatomic,strong) UIView *greenView; -@end - -@implementation SecondViewController - -- (void)viewDidLoad { - [super viewDidLoad]; - - self.view.backgroundColor = [UIColor whiteColor]; - - self.redView = [[UIView alloc]init]; - self.redView.backgroundColor = [UIColor redColor]; - [self.view addSubview:self.redView]; - - self.greenView = [[UIView alloc]init]; - self.greenView.backgroundColor = [UIColor greenColor]; - [self.view addSubview:self.greenView]; - - [self.redView jc_makeLayout:^(JCFrameMake *make) { - -// 25. left and right and top and bottom -// make.left.jc_equalTo(50); -// make.right.jc_equalTo(-50); -// make.top.jc_equalTo(50); -// make.bottom.jc_equalTo(-50); - - make.left.top.width.height.jc_equalTo(100); - -// 24. right and top and bottom and width -// make.right.jc_equalTo(-50); -// make.top.jc_equalTo(50); -// make.bottom.jc_equalTo(-50); -// make.width.jc_equalTo(100); - -// 23. left and top and bottom and width -// make.left.jc_equalTo(50); -// make.top.jc_equalTo(50); -// make.bottom.jc_equalTo(-50); -// make.width.jc_equalTo(100); - -// 22. left and right and bottom and height -// make.left.jc_equalTo(50); -// make.right.jc_equalTo(-50); -// make.bottom.jc_equalTo(-50); -// make.height.jc_equalTo(100); - -// 21. left and right and top and height -// make.left.jc_equalTo(50); -// make.right.jc_equalTo(-50); -// make.top.jc_equalTo(50); -// make.height.jc_equalTo(100); - - -// 20. right and bottom and width and height -// make.right.jc_equalTo(-50); -// make.bottom.jc_equalTo(-50); -// make.height.jc_equalTo(100); -// make.width.jc_equalTo(100); - -// 19. right and top and width and height -// make.right.jc_equalTo(-50); -// make.top.jc_equalTo(50); -// make.height.jc_equalTo(100); -// make.width.jc_equalTo(100); - -// 18. left and bottom and width and height -// make.left.jc_equalTo(50); -// make.bottom.jc_equalTo(-50); -// make.height.jc_equalTo(100); -// make.width.jc_equalTo(100); -// -// 17. left and top and width and height -// make.left.jc_equalTo(50); -// make.top.jc_equalTo(50); -// make.height.jc_equalTo(100); -// make.width.jc_equalTo(100); - -// 16. centerY and right and width and height -// make.centerY.jc_equalTo(100); -// make.right.jc_equalTo(-100); -// make.width.jc_equalTo(100); -// make.height.jc_equalTo(100); - -// 15. centerY and left and width and height -// make.centerY.jc_equalTo(100); -// make.left.jc_equalTo(100); -// make.width.jc_equalTo(100); -// make.height.jc_equalTo(100); - -// 14. centerX and bottom and width and height -// make.centerX.jc_equalTo(100); -// make.bottom.jc_equalTo(-50); -// make.width.jc_equalTo(100); -// make.height.jc_equalTo(100); - -// 13. centerX and top and width and height -// make.centerX.jc_equalTo(100); -// make.top.jc_equalTo(100); -// make.width.jc_equalTo(100); -// make.height.jc_equalTo(100); - -// 12. centerX and centerY and width and height -// make.centerX.jc_equalTo(100); -// make.centerY.jc_equalTo(100); -// make.width.jc_equalTo(100); -// make.height.jc_equalTo(100); - -// 11. right and bottom and size -// make.right.jc_equalTo(-50); -// make.bottom.jc_equalTo(-50); -// make.size.jc_equalTo(CGSizeMake(100, 100)); - -// 10. right and top and size -// make.right.jc_equalTo(-50); -// make.top.jc_equalTo(100); -// make.size.jc_equalTo(CGSizeMake(100, 100)); - -// 9. left and bottom and size -// make.left.jc_equalTo(100); -// make.bottom.jc_equalTo(50); -// make.size.jc_equalTo(CGSizeMake(100, 100)); - -// 8. left and top and size -// make.left.jc_equalTo(100); -// make.top.jc_equalTo(100); -// make.size.jc_equalTo(CGSizeMake(100, 100)); - -// 7. centerY and right and size -// make.centerY.jc_equalTo(100); -// make.right.jc_equalTo(-50); -// make.size.jc_equalTo(CGSizeMake(100, 100)); - -// 6. centerY and left and size -// make.centerY.jc_equalTo(200); -// make.left.jc_equalTo(100); -// make.size.jc_equalTo(CGSizeMake(200, 200)); - -// 5. centerX and bottom and size -// make.centerX.jc_equalTo(100); -// make.size.jc_equalTo(CGSizeMake(100, 100)); -// make.bottom.jc_equalTo(-50); - -// 4. centerX and top and size -// make.centerX.jc_equalTo(100); -// make.top.jc_equalTo(50); -// make.size.jc_equalTo(CGSizeMake(100, 100)); - -// 3.centerX and centerY and size -// make.centerX.jc_equalTo(100); -// make.centerY.jc_equalTo(100); -// make.size.jc_equalTo(CGSizeMake(100, 100)); - -// 2. center and width and height -// make.center.jc_equalTo(CGPointMake(100, 100)); -// make.width.jc_equalTo(200); -// make.height.jc_equalTo(200); - -// 1. center and size -// make.center.jc_equalTo(CGPointMake(100, 100)); -// make.size.jc_equalTo(CGSizeMake(100, 100)); - }]; - -// [self.greenView jc_makeLayout:^(JCFrameMake *make) { -// make.left.jc_equalTo(50); -// make.width.jc_equalTo(100); -// -// make.top.jc_equalTo(50); -// make.height.jc_equalTo(100); -// }]; - - NSLog(@"self.redView.frame = %@",[NSValue valueWithCGRect:self.redView.frame]); -} - --(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ - [self dismissViewControllerAnimated:YES completion:nil]; -} - -@end diff --git a/JCFrameLayout/ViewController.m b/JCFrameLayout/ViewController.m index 6c5f071..f2c31bf 100644 --- a/JCFrameLayout/ViewController.m +++ b/JCFrameLayout/ViewController.m @@ -7,12 +7,13 @@ // #import "ViewController.h" -#import "Masonry.h" - #import "SecondViewController.h" -@interface ViewController () +#import "JCFrameLayout.h" +@interface ViewController () +@property (nonatomic,strong) UITableView *tableView; +@property (nonatomic,strong) NSArray*> *datasource; @end @implementation ViewController @@ -22,13 +23,63 @@ - (void)viewDidLoad { self.view.backgroundColor = [UIColor whiteColor]; + [self.view addSubview:self.tableView]; + + [self.tableView jc_makeLayout:^(JCFrameMake *make) { + make.left.jc_equalTo(0); + make.top.jc_equalTo(0); + make.right.jc_equalTo(0); + make.bottom.jc_equalTo(0); + }]; } +- (UITableView *)tableView{ + if (!_tableView) { + _tableView = [[UITableView alloc]init]; + [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; + _tableView.delegate = self; + _tableView.dataSource = self; + } + return _tableView; +} -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ - SecondViewController *vc = [[SecondViewController alloc]init]; - [self presentViewController:vc animated:YES completion:nil]; +#pragma mark - UITableViewDataSource +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ + return self.datasource.count; } +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; + + NSDictionary *dict = self.datasource[indexPath.item]; + cell.textLabel.text = dict[@"title"]; + + return cell; +} + +#pragma mark - UITableViewDelegate +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ + NSDictionary *dict = self.datasource[indexPath.item]; + NSString *cls = dict[@"cls"]; + Class class = NSClassFromString(cls); + UIViewController *vc = [[class alloc]init]; + vc.title = dict[@"title"]; + [self.navigationController pushViewController:vc animated:YES]; +} +- (NSArray *> *)datasource{ + if (!_datasource) { + NSMutableArray *array = [NSMutableArray array]; + + [array addObject:@{@"title":@"左,上,右,下",@"cls":@"ExampleVC1"}]; + [array addObject:@{@"title":@"九宫格(绝对布局)",@"cls":@"ExampleVC2"}]; + [array addObject:@{@"title":@"九宫格(相对布局)",@"cls":@"ExampleVC3"}]; + [array addObject:@{@"title":@"五千个方块(绝对布局)",@"cls":@"ExampleVC4"}]; + [array addObject:@{@"title":@"五千个方块(相对布局)",@"cls":@"ExampleVC5"}]; + [array addObject:@{@"title":@"开发过程测试使用(非Demo)",@"cls":@"DevTest"}]; + + _datasource = [array copy]; + } + return _datasource; +} @end diff --git a/README.md b/README.md index 163d948..4fc5d7e 100644 --- a/README.md +++ b/README.md @@ -1 +1,272 @@ -# JCFrameLayout \ No newline at end of file +# JCFrameLayout + +JCFrameLayout是一个类似Masonry的布局工具,与Masonry不同的是JCFrameLayout采用的是Frame布局而非约束布局。 + +感兴趣的可以加QQ群交流:70835656 (JC开源项目交流) + + +# 性能对比 + +暂时省略,后面补充 + +# 特性 + +* **高性能** : 原始的Frame布局,避免AutoLayout带来的性能问题 +* **无侵入性** : 零继承,通过UIView的Category实现 +* **使用简单** : 使用大家熟悉的Masonry语法 + +# 使用方式 + +### 上、下、左、右、中间效果 + +``` +//靠左边的视图 +UIView *leftView = [[UIView alloc]init]; + leftView.backgroundColor = radomColor; + [self.view addSubview:leftView]; + leftView.jc_debug_key = @"leftView"; + [leftView jc_makeLayout:^(JCFrameMake *make) { + make.width.jc_equalTo(50); + make.top.jc_equalTo(50 + 64); + make.bottom.jc_equalTo(-50); + make.left.jc_equalTo(0); + }]; + + //靠右边的视图 + UIView *rightView = [[UIView alloc]init]; + rightView.backgroundColor = radomColor; + [self.view addSubview:rightView]; + rightView.jc_debug_key = @"rightView"; + [rightView jc_makeLayout:^(JCFrameMake *make) { + make.width.jc_equalTo(50); + make.top.jc_equalTo(50 + 64); + make.bottom.jc_equalTo(-50); + make.right.jc_equalTo(0); + }]; + + //靠顶部的视图 + UIView *topView = [[UIView alloc]init]; + topView.backgroundColor = radomColor; + [self.view addSubview:topView]; + topView.jc_debug_key = @"topView"; + [topView jc_makeLayout:^(JCFrameMake *make) { + make.top.jc_equalTo(64); + make.height.jc_equalTo(50); + make.left.jc_equalTo(50); + make.right.jc_equalTo(-50); + }]; + + //靠底部的视图 + UIView *bottomView = [[UIView alloc]init]; + bottomView.backgroundColor = radomColor; + [self.view addSubview:bottomView]; + bottomView.jc_debug_key = @"bottomView"; + [bottomView jc_makeLayout:^(JCFrameMake *make) { + make.height.jc_equalTo(50); + make.left.jc_equalTo(50); + make.right.jc_equalTo(-50); + make.bottom.jc_equalTo(0); + }]; + + //中间的内切视图 + UIView *centerView = [[UIView alloc]init]; + centerView.backgroundColor = radomColor; + [self.view addSubview:centerView]; + centerView.jc_debug_key = @"centerView"; + [centerView jc_makeLayout:^(JCFrameMake *make) { + make.left.equalTo(leftView.jc_right); + make.top.equalTo(topView.jc_bottom); + make.right.equalTo(rightView.jc_left); + make.bottom.equalTo(bottomView.jc_top); + }]; + [self.view sendSubviewToBack:centerView]; +``` + +### 九宫格(绝对布局,每个方块都相对于屏幕左上角进行布局) + +``` +//列数 + int column = 3; + //内间距 + CGFloat padding = 20; + //每个方块尺寸 + CGFloat width = (JC_SCREEN_WIDTH - padding * (column + 1))/column; + CGFloat height = width; + + for (int i = 0; i< 9; i++) { + + //计算X左边 + int col = i % column; + CGFloat x = col * (width + padding) + padding; + + //计算Y左边 + int row = i / column; + CGFloat y = row * (height + padding) + padding + 64; + + UIView *view = [[UIView alloc]init]; + [self.view addSubview:view]; + view.backgroundColor = radomColor; + + //使用JCFrameLayout进行布局 + [view jc_makeLayout:^(JCFrameMake *make) { + make.width.jc_equalTo(width); + make.height.jc_equalTo(height); + make.left.jc_equalTo(x); + make.top.jc_equalTo(y); + }]; + } +``` + +### 九宫格(相对布局,每个方块都相对于前一个方块进行布局) + +``` +//列数 + int column = 3; + //内间距 + CGFloat padding = 20; + //每个方块尺寸 + CGFloat width = (JC_SCREEN_WIDTH - padding * (column + 1))/column; + CGFloat height = width; + + for (int idx = 0; idx < 9; idx++) { + + //计算所处行数 + int row = idx / column; + //计算所处列数 + int col = idx % column; + + UIView *view = [[UIView alloc]init]; + view.jc_debug_key = [NSString stringWithFormat:@"view_%zd",idx]; + view.backgroundColor = radomColor; + + if (row == 0 && col == 0) { + //如果是第一行第一个列,则相对屏幕左上角进行布局 + [view jc_makeLayout:^(JCFrameMake *make) { + make.left.jc_equalTo(padding); + make.top.jc_equalTo(padding + 64); + make.width.jc_equalTo(width); + make.height.jc_equalTo(height); + }]; + }else{ + //其他方块相对于前一个方块进行布局 + //取出前一个方块 + UIView *lastView = [self.view.subviews lastObject]; + + if (col == 0) { //和前一个方块在同一行 + [view jc_makeLayout:^(JCFrameMake *make) { + make.top.equalTo(lastView.jc_bottom).jc_offset(padding); + make.left.jc_equalTo(padding); + make.width.jc_equalTo(width); + make.height.jc_equalTo(height); + }]; + }else{ //和前一个方块不再同一行 + [view jc_makeLayout:^(JCFrameMake *make) { + make.left.equalTo(lastView.jc_right).jc_offset(padding); + make.top.equalTo(lastView); + make.width.jc_equalTo(width); + make.height.jc_equalTo(height); + }]; + } + } + [self.view addSubview:view]; + } +``` + + + +# 注意点 + +### 相对布局限制 + +相对只能相对于同一个superView或superView进行相,不可跨视图进行。 + +![](https://github.com/devjackcat/JCFrameLayout/blob/master/images/image1.png) + +上图中,View1为View2的superView, View2为View3和View4的superView,当需要对View3进行相对布局时,只能相对于View4和View2进行,不能相对于View1进行。 + +### 性能问题 + +由于计算复杂度的影响,绝对布局性能会优于相对布局。 + +# 安装 + +### CocoaPods + +1. 在Podfile文件中添加 `pod 'JCFrameLayout'` +2. 执行 `pod install` 或 `pod update` 命令 +3. 引文头文件 `#import ` + +### 手动安装 + +1. 下载JCFrameLayout项目 +2. 将JCFrameLayout文件夹拖入到项目中 +3. 引文头文件 `#import "JCFrameLayout.h"` + +# 系统要求 + +iOS8 以上系统 + +# 历史版本 + +### V2.0.0 + +实现多视图的相对布局 + +``` +[centerView jc_makeLayout:^(JCFrameMake *make) { + make.left.equalTo(leftView.jc_right); + make.top.equalTo(topView.jc_bottom); + make.right.equalTo(rightView.jc_left); + make.bottom.equalTo(bottomView.jc_top); + }]; +``` + +### V1.1.2 +完善了单视图的链式语法,可以实现这样的的效果 + +``` +[self.redView jc_makeLayout:^(JCFrameMake *make) { + make.left.top.width.height.jc_equalTo(100); + }]; +``` + +### V1.1.1 +jc_equalTo()时自动将基本类型进行装箱 + +可以将V1.1.0的代码简化为: + +``` +[self.redView jc_makeLayout:^(JCFrameMake *make) { + make.center.jc_equalTo(CGPointMake(100, 100)); + make.size.jc_equalTo(CGSizeMake(100, 100)); + }]; +``` + +### V1.1.0 +增加了center,size两个复合属性的支持 + +``` +[self.redView jc_makeLayout:^(JCFrameMake *make) { + make.center.jc_equalTo([NSValue valueWithCGPoint:CGPointMake(100, 100)]); + make.size.jc_equalTo([NSValue valueWithCGSize:CGSizeMake(100, 100)]); +}]; +``` + +### V1.0.0 +实现了单视图的基本布局,支持6个布局属性left,top,width,height,centerX,centerY,可以链式语法还支持不完善,下面是布局的一个例子: + +``` +[self.redView jc_makeLayout:^(JCFrameMake *make) { + make.left.jc_equalTo(@50); + make.top.jc_equalTo(@50); + make.width.jc_equalTo(@100); + make.height.jc_equalTo(@100); + }]; +``` + + +# 信息反馈 + +* 使用中发现Bug请在Issues提出,或者邮件告知我,我将尽快修复 +* 使用中有好的建议也可以在Issues提出,或邮件告知我 + diff --git a/images/image1.png b/images/image1.png new file mode 100644 index 0000000..f6aa794 Binary files /dev/null and b/images/image1.png differ