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.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Otbivnoe committed Aug 1, 2017
2 parents 4d1e6f9 + 48f63b6 commit 11c7f3e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 28 deletions.
46 changes: 31 additions & 15 deletions Example/FramezillaExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

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

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

view.addSubview(content1)
view.addSubview(content2)
view.addSubview(content3)
view.addSubview(scrollView)
scrollView.addSubview(content2)

// view.addSubview(content3)
}

override func viewDidLayoutSubviews() {
Expand All @@ -48,20 +53,31 @@ class ViewController: UIViewController {
// maker.centerY(between: content2, content1)
// maker.centerX()
// }

content1.configureFrame { maker in
maker.edges(top: 0, left: 0, bottom: 0)
maker.width(50)


// content1.configureFrame { maker in
// maker.edges(top: 0, left: 0, bottom: 0)
// maker.width(50)
// }
//
// content2.configureFrame { maker in
// maker.edges(top: 0, bottom: 0, right: 0)
// maker.width(200)
// }
//
// content3.configureFrame { maker in
// maker.size(width: 20, height: 70)
// maker.centerX(between: content1, content2)
// maker.centerY()
// }

scrollView.configureFrame { maker in
maker.margin(20)
}

content2.configureFrame { maker in
maker.edges(top: 0, bottom: 0, right: 0)
maker.width(200)
}

content3.configureFrame { maker in
maker.size(width: 20, height: 70)
maker.centerX(between: content1, content2)
maker.size(width: 100, height: 100)
maker.left()
maker.centerY()
}
}
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.2.0"
spec.version = "2.2.1"
spec.summary = "Comfortable syntax for working with frames."

spec.homepage = "https://github.com/Otbivnoe/Framezilla"
Expand Down
20 changes: 11 additions & 9 deletions Sources/MakerHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ fileprivate extension UIView {
extension Maker {

func convertedValue(for type: RelationType, with view: UIView) -> CGFloat {
var convertedRect: CGRect {
if let superScrollView = self.view.superview as? UIScrollView, view is UIScrollView {
return CGRect(x: 0,
y: 0,
width: superScrollView.contentSize.width,
height: superScrollView.contentSize.height)
}
else {
return self.view.superview!.convert(view.frame, from: view.superview)

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

var convertedRect = rect
if let superScrollView = self.view.superview as? UIScrollView, view is UIScrollView, superScrollView.contentSize != .zero {
convertedRect.size.width = superScrollView.contentSize.width
convertedRect.size.height = superScrollView.contentSize.height
}

switch type {
Expand Down
20 changes: 17 additions & 3 deletions Tests/ScrollViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class ScrollViewTests: XCTestCase {
scrollView.contentSize = CGSize(width: 300, height: 300)
}

func testThanCorrectlyConfigures_edges_relativelyScrollView() {
func testThanCorrectlyConfigures_edges_relativelyScrollViewWithNonZeroContentSize() {

let view = UIView(frame: .zero)
scrollView.addSubview(view)
Expand All @@ -29,7 +29,21 @@ final class ScrollViewTests: XCTestCase {
XCTAssertEqual(view.frame, CGRect(x: 10, y: 20, width: 260, height: 240))
view.removeFromSuperview()
}


func testThanCorrectlyConfigures_edges_relativelyScrollViewWithZeroContentSize() {
scrollView.contentSize = .zero

let view = UIView(frame: .zero)
scrollView.addSubview(view)

view.configureFrame { maker in
maker.edges(top: 20, left: 10, bottom: 40, right: 30)
}

XCTAssertEqual(view.frame, CGRect(x: 10, y: 20, width: 60, height: 40))
view.removeFromSuperview()
}

func testThanCorrectlyConfigures_center_relativelyScrollView() {

let view = UIView(frame: .zero)
Expand All @@ -44,7 +58,7 @@ final class ScrollViewTests: XCTestCase {
view.removeFromSuperview()
}

func testThanCorrectlyConfiguresFewSubviewTogeter() {
func testThanCorrectlyConfiguresFewSubviewTogether() {

let view1 = UIView(frame: .zero)
let view2 = UIView(frame: .zero)
Expand Down

0 comments on commit 11c7f3e

Please sign in to comment.