简体   繁体   中英

UIView origin is not equal to zero

I setup a view controller scene with interface builder. I add a view to my controller and add a custom class (CustomView) to it.

在此处输入图片说明

The view controller code

class ViewController: UIViewController {

    @IBOutlet var myCustomView: CustomView!
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    override func viewDidAppear(animated: Bool) {
        print(myCustomView.frame.origin)
    }

}

The question

Why the origin of myCustomView is equal to (-4.0, 64.0) and not (0, 64) ?

when you add the constraints,your constraints to margin remains unchecked. Because of constraints to margin it gives you a frame that starts with (-4.0,64.0) like that...

Try to pinned all your edges without constraints to margin that will solve your problem ..

For more guide about constraints to margin, check this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM