layoutBox / PinLayout

Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vCenter() incorrectly alters the anchor point.

MaruthiBasava opened this issue · comments

Screen Shot 2019-03-20 at 11 18 20 PM

Screen Shot 2019-03-20 at 11 18 29 PM

Box 1 is Red
Box 2 is Blue
Box 4 is Pink.

As you can see, the center anchor point of box4 should be on the bottom-right of box2, but its way off. I tested it without vCenter, and it worked perfectly.

@MaruthiBasava, could you show me your view's initialization codes (ref: addSubView, ...). There is maybe an issue, but I'm unable to reproduce your issue.

If you could share the whole UIViewController class, it would be even better.

import UIKit
import PlaygroundSupport

class ViewController: UIViewController {
    
    lazy var box1 : UIView = {
        let v = UIView()
        v.backgroundColor = .red
        return v
    }()
    
    lazy var box2 : UIView = {
        let v = UIView()
        v.backgroundColor = .blue
        return v
    }()
    
    lazy var box3 : UIView = {
        let v = UIView()
        v.backgroundColor = .green
        return v
    }()
    
    lazy var box4 : UIView = {
        let v = UIView()
        v.backgroundColor = .red
        v.alpha = 0.5
        return v
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .white
        
        view.addSubview(box1)
        view.addSubview(box2)
        view.addSubview(box3)
        view.addSubview(box4)
        
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
            box1.pin.left(10).size(100)
            box2.pin.left(to: box1.edge.right)
            .vCenter(to: view.edge.vCenter).size(100).marginLeft(10)
            box4.pin.center(to: box2.anchor.bottomRight).size(20)
    
    }
    
}



PlaygroundPage.current.liveView = ViewController()

Run this in the playground.

There is some limitation of using PinLayout in Playgrounds. See
https://github.com/layoutBox/PinLayout/blob/master/docs/xcode_playground.md

Issues was previously fixed by calling layout() method, but looks like there is new issues 😕

Actually you're right! calling layout() fixed my issue. Thank you so much!
Also what are other issues that may be present within the Playgrounds? My company is currently prototyping the UI on playground for efficiency, so I would love to be aware of it. Thank you once again.

Good to know, that it fixed the issue, because I was scared that there was other issue with playgrounds. ARC behave differently in playgrounds, it doesn't release object immediately, but delay their destruction.