Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/2.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Ermolenko committed Nov 30, 2017
2 parents f652993 + bee60f3 commit 1882918
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 43 deletions.
79 changes: 73 additions & 6 deletions Example/FramezillaExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,89 @@
objects = {

/* Begin PBXBuildFile section */
841354611FCFEC02009F2947 /* Framezilla.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8413545E1FCFEA51009F2947 /* Framezilla.framework */; };
841354621FCFEC02009F2947 /* Framezilla.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8413545E1FCFEA51009F2947 /* Framezilla.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
8442F9531EC75C9C00B72551 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8442F9521EC75C9C00B72551 /* AppDelegate.swift */; };
8442F9551EC75C9C00B72551 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8442F9541EC75C9C00B72551 /* ViewController.swift */; };
8442F9581EC75C9C00B72551 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8442F9561EC75C9C00B72551 /* Main.storyboard */; };
8442F95A1EC75C9C00B72551 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8442F9591EC75C9C00B72551 /* Assets.xcassets */; };
8442F95D1EC75C9C00B72551 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8442F95B1EC75C9C00B72551 /* LaunchScreen.storyboard */; };
8442F96B1EC75CC400B72551 /* Framezilla.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8442F96A1EC75CC400B72551 /* Framezilla.framework */; };
8442F96C1EC75CC400B72551 /* Framezilla.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8442F96A1EC75CC400B72551 /* Framezilla.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
8413545D1FCFEA51009F2947 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 841354581FCFEA51009F2947 /* Framezilla.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 11FB41321D844D2C00700A40;
remoteInfo = "Framezilla iOS";
};
8413545F1FCFEA51009F2947 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 841354581FCFEA51009F2947 /* Framezilla.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 115972141D8450F500BC5C20;
remoteInfo = FramezillaTests;
};
841354631FCFEC02009F2947 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 841354581FCFEA51009F2947 /* Framezilla.xcodeproj */;
proxyType = 1;
remoteGlobalIDString = 11FB41311D844D2B00700A40;
remoteInfo = "Framezilla iOS";
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
8442F96D1EC75CC400B72551 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
8442F96C1EC75CC400B72551 /* Framezilla.framework in Embed Frameworks */,
841354621FCFEC02009F2947 /* Framezilla.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
841354581FCFEA51009F2947 /* Framezilla.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Framezilla.xcodeproj; path = ../Framezilla.xcodeproj; sourceTree = "<group>"; };
8442F94F1EC75C9C00B72551 /* FramezillaExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FramezillaExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
8442F9521EC75C9C00B72551 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
8442F9541EC75C9C00B72551 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
8442F9571EC75C9C00B72551 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
8442F9591EC75C9C00B72551 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
8442F95C1EC75C9C00B72551 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
8442F95E1EC75C9C00B72551 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8442F96A1EC75CC400B72551 /* Framezilla.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Framezilla.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
8442F94C1EC75C9C00B72551 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8442F96B1EC75CC400B72551 /* Framezilla.framework in Frameworks */,
841354611FCFEC02009F2947 /* Framezilla.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
841354591FCFEA51009F2947 /* Products */ = {
isa = PBXGroup;
children = (
8413545E1FCFEA51009F2947 /* Framezilla.framework */,
841354601FCFEA51009F2947 /* FramezillaTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
8442F9461EC75C9C00B72551 = {
isa = PBXGroup;
children = (
8442F96A1EC75CC400B72551 /* Framezilla.framework */,
841354581FCFEA51009F2947 /* Framezilla.xcodeproj */,
8442F9511EC75C9C00B72551 /* FramezillaExample */,
8442F9501EC75C9C00B72551 /* Products */,
);
Expand Down Expand Up @@ -98,6 +131,7 @@
buildRules = (
);
dependencies = (
841354641FCFEC02009F2947 /* PBXTargetDependency */,
);
name = FramezillaExample;
productName = FramezillaExample;
Expand Down Expand Up @@ -131,13 +165,36 @@
mainGroup = 8442F9461EC75C9C00B72551;
productRefGroup = 8442F9501EC75C9C00B72551 /* Products */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = 841354591FCFEA51009F2947 /* Products */;
ProjectRef = 841354581FCFEA51009F2947 /* Framezilla.xcodeproj */;
},
);
projectRoot = "";
targets = (
8442F94E1EC75C9C00B72551 /* FramezillaExample */,
);
};
/* End PBXProject section */

/* Begin PBXReferenceProxy section */
8413545E1FCFEA51009F2947 /* Framezilla.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = Framezilla.framework;
remoteRef = 8413545D1FCFEA51009F2947 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
841354601FCFEA51009F2947 /* FramezillaTests.xctest */ = {
isa = PBXReferenceProxy;
fileType = wrapper.cfbundle;
path = FramezillaTests.xctest;
remoteRef = 8413545F1FCFEA51009F2947 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
8442F94D1EC75C9C00B72551 /* Resources */ = {
isa = PBXResourcesBuildPhase;
Expand All @@ -163,6 +220,14 @@
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
841354641FCFEC02009F2947 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = "Framezilla iOS";
targetProxy = 841354631FCFEC02009F2947 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
8442F9561EC75C9C00B72551 /* Main.storyboard */ = {
isa = PBXVariantGroup;
Expand Down Expand Up @@ -293,6 +358,7 @@
8442F9621EC75C9C00B72551 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = FramezillaExample/Info.plist;
Expand All @@ -307,6 +373,7 @@
8442F9631EC75C9C00B72551 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = FramezillaExample/Info.plist;
Expand Down
39 changes: 21 additions & 18 deletions Example/FramezillaExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,43 @@ import Framezilla

class ViewController: UIViewController {

let scrollView = UIScrollView()

let content1 = UIView()
let content2 = UIView()
let content3 = UIView()

let testView = UIView()


override func viewDidLoad() {
super.viewDidLoad()

if #available(iOS 11.0, *) {
additionalSafeAreaInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
}

scrollView.backgroundColor = .yellow
scrollView.contentSize = CGSize(width: 500, height: 1000)
view.backgroundColor = .white

content1.backgroundColor = .red
content2.backgroundColor = .green
content3.backgroundColor = .black
content2.backgroundColor = .black
content3.backgroundColor = .green

view.backgroundColor = .yellow
view.addSubview(content1)
view.addSubview(content2)
view.addSubview(content3)
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

content3.configureFrame { maker in
maker.size(width: 50, height: 50)
maker.top(inset: 100)
maker.centerX(between: view.nui_left, view.nui_right)
}

content1.configureFrame { maker in
maker.top(to: nui_safeArea)
maker.bottom(to: nui_safeArea)
maker.right(to: nui_safeArea)
maker.left(to: nui_safeArea)
maker.bottom(inset: 100)
maker.right().left()
maker.height(10)
}

content2.configureFrame { maker in
maker.size(width: 50, height: 50)
maker.centerX()
maker.centerY(between: content1.nui_bottom, view.nui_bottom)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Framezilla.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "Framezilla"
spec.version = "2.3.0"
spec.version = "2.4.0"
spec.summary = "Comfortable syntax for working with frames."

spec.homepage = "https://github.com/Otbivnoe/Framezilla"
Expand Down
60 changes: 46 additions & 14 deletions Sources/Maker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -683,20 +683,36 @@ public final class Maker {
/// - returns: `Maker` instance for chaining relations.

@discardableResult public func centerY(between view1: UIView, _ view2: UIView) -> Maker {
let topView = view1.frame.maxY > view2.frame.minY ? view2 : view1
let bottomView = topView === view1 ? view2 : view1
return self.centerY(between: topView.nui_bottom, bottomView.nui_top)
}

/// Creates centerY relation between two relation views.
///
/// Use this method when you want to configure centerY point between two relations views.
///
/// - parameter relationView1: The first relation view between which you set `centerY` relation.
/// - parameter relationView2: The second relation view between which you set `centerY` relation.
///
/// - returns: `Maker` instance for chaining relations.

@discardableResult public func centerY(between relationView1: RelationView<VerticalRelation>,
_ relationView2: RelationView<VerticalRelation>) -> Maker {
let handler = { [unowned self] in
let bottomView = view1.frame.minY > view2.frame.minY ? view1 : view2
let topView = bottomView === view1 ? view2 : view1
let topY = self.convertedValue(for: .bottom, with: topView)
let bottomY = self.convertedValue(for: .top, with: bottomView)
let y1 = self.convertedValue(for: relationView1.relationType, with: relationView1.view)
let y2 = self.convertedValue(for: relationView2.relationType, with: relationView2.view)

let topY = y1 < y2 ? y1 : y2
let bottomY = y1 >= y2 ? y1 : y2

let y = bottomY - (bottomY - topY)/2 - self.newRect.height/2
self.newRect.setValue(y, for: .top)
}
handlers.append((.low, handler))
return self
}

/// Creates centerX relation to superview.
///
/// Use this method when you want to join centerX of current view with centerX of superview.
Expand Down Expand Up @@ -746,20 +762,36 @@ public final class Maker {
/// - returns: `Maker` instance for chaining relations.

@discardableResult public func centerX(between view1: UIView, _ view2: UIView) -> Maker {
let leftView = view1.frame.maxX > view2.frame.minX ? view2 : view1
let rightView = leftView === view1 ? view2 : view1
return self.centerX(between: leftView.nui_right, rightView.nui_left)
}

/// Creates centerX relation between two relation views.
///
/// Use this method when you want to configure centerX point between two relations views.
///
/// - parameter relationView1: The first relation view between which you set `centerX` relation.
/// - parameter relationView2: The second relation view between which you set `centerX` relation.
///
/// - returns: `Maker` instance for chaining relations.

@discardableResult public func centerX(between relationView1: RelationView<HorizontalRelation>,
_ relationView2: RelationView<HorizontalRelation>) -> Maker {
let handler = { [unowned self] in
let rightView = view1.frame.minX > view2.frame.minX ? view1 : view2
let leftView = rightView === view1 ? view2 : view1
let leftX = self.convertedValue(for: .right, with: leftView)
let rightX = self.convertedValue(for: .left, with: rightView)
let x1 = self.convertedValue(for: relationView1.relationType, with: relationView1.view)
let x2 = self.convertedValue(for: relationView2.relationType, with: relationView2.view)

let rightX = x1 < x2 ? x1 : x2
let leftX = x1 >= x2 ? x1 : x2

let x = rightX - (rightX - leftX)/2 - self.newRect.width/2
self.newRect.setValue(x, for: .left)
}
handlers.append((.low, handler))
return self
}

/// Just setting centerX.
///
/// - parameter value: The value for setting centerX.
Expand Down
3 changes: 1 addition & 2 deletions Sources/MakerHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ fileprivate extension UIView {
extension Maker {

func convertedValue(for type: RelationType, with view: UIView) -> CGFloat {

var rect: CGRect {
if let superview = self.view.superview, superview === view, superview.superview == nil {
if let superview = self.view.superview, superview === view {
return CGRect(origin: .zero, size: superview.frame.size)
}

Expand Down
22 changes: 20 additions & 2 deletions Tests/MakerCenterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@ class MakerCenterTests: BaseTest {
}

XCTAssertEqual(view3.frame, CGRect(x: 190, y: 235, width: 20, height: 30))

view3.frame = .zero
view3.configureFrame { maker in
maker.size(width: 20, height: 30)
maker.centerX(between: view2, view1)
maker.centerY()
}

XCTAssertEqual(view3.frame, CGRect(x: 190, y: 235, width: 20, height: 30))
}

func testThanCorrectlyConfigures_centerY_betweenTwoViews() {

let view1 = UIView()
Expand Down Expand Up @@ -68,8 +77,17 @@ class MakerCenterTests: BaseTest {
}

XCTAssertEqual(view3.frame, CGRect(x: 235, y: 190, width: 30, height: 20))

view3.frame = .zero
view3.configureFrame { maker in
maker.size(width: 30, height: 20)
maker.centerY(between: view2, view1)
maker.centerX()
}

XCTAssertEqual(view3.frame, CGRect(x: 235, y: 190, width: 30, height: 20))
}

/* super centerX without superview for related view */

func testThatCorrectlyConfigures_centerX_forRelativelySuperViewWithoutOwnSuperView() {
Expand Down
Loading

0 comments on commit 1882918

Please sign in to comment.