简体   繁体   中英

ios Constraints Not Working

I have a scrollView with the following constraints:

在此处输入图片说明

I am adding a View with the following constraints to it. Basically CameraView and MyPicImageView are supposed to fill the whole View, FlipCamBtn is supposed to be in the Lower Right hand corner, Button in the Lower Left Hand Corner, Save Image Btn in the Top Right corner and Capture in the Bottom Center of the screen.:

在此处输入图片说明

I have the following code which adds this View to the scrollView.

mainScrollView.hidden = false
    var CameraView : CameraViewController = CameraViewController(nibName : "CameraViewController", bundle: nil)
    self.addChildViewController(CameraView)
    self.mainScrollView.addSubview(CameraView.view)
    CameraView.didMoveToParentViewController(self)

The problem is that my View appears too large and the buttons are off the screen.

Your code does not add constraints between self.mainScrollView and CameraViewController.view , the view will be added as is in its superview.

This mean the size of the xib will be the size of the view at runtime (except if some subviews constraints force the parent view to resize). Right now the xib you are seeing is not showing the results of the constraints you have added to it because there is this orange arrow at the top right of the views list in your screenshot. First try to fix the warning by running Update frames .

If this does not solve anything you'll have to add constraints between CameraViewController.view and self.mainScrollView programmatically. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html

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