私はこのエラーを取得する:ボタンを押した結果である、その下のUIView誤動作
Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors and because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'
lazy var registerButton: UIButton = {
let rButton = UIButton(type: .system)
rButton.frame = CGRect(x: 210, y: 600, width: 100, height: 50)
rButton.setTitle("REGISTER", for: .normal)
rButton.backgroundColor = UIColor.white
rButton.translatesAutoresizingMaskIntoConstraints = false
rButton.setTitleColor(UIColor.black, for: .normal)
rButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 20)
rButton.layer.cornerRadius = 20
rButton.layer.borderWidth = 2
rButton.addTarget(self, action: #selector(regSegue), for: .touchUpInside)
return rButton
}()
を参照してくださいコード(ボタン押下上記のコードはある):
func regSegue() {
let page = UIPageViewController()
present(page, animated: true, completion: nil)
page.view.backgroundColor = UIColor .white;
// let loginInputContainerView: UIView = UIView(frame: CGRect(x: 12, y: 225, width: 350, height: 200.00));
let inputContainerView = UIView()
inputContainerView.backgroundColor = UIColor.blue
inputContainerView.layer.cornerRadius = 5
inputContainerView.layer.masksToBounds = true
inputContainerView.translatesAutoresizingMaskIntoConstraints = false
// need x,y,width,height
inputContainerView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
inputContainerView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
inputContainerView.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -24).isActive = true
inputContainerView.heightAnchor.constraint(equalToConstant: 150).isActive = true
page.view.addSubview(inputContainerView)
}
私は迷っています。
ここに追加する必要がありますか?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// will allow me to put a image as my UI background instead of a color
// will make sure background image scales to screen size
UIGraphicsBeginImageContext(self.view.frame.size)
UIImage(named: "BestBackground")?.draw(in: self.view.bounds)
// self is the screen we are working on
//view is there to specify the controller view or the view that the controller manages
//bounds describes the views location and size
if let image: UIImage = UIGraphicsGetImageFromCurrentImageContext(){
UIGraphicsEndImageContext()
self.view.backgroundColor = UIColor(patternImage: image)
}else{
// debugging incase image isnt found
UIGraphicsEndImageContext()
debugPrint("Image not available")
}
// will add subiviews to the screen
view.addSubview(loginButton)
view.addSubview(registerButton)
}
//will give you white status bar
override var preferredStatusBarStyle: UIStatusBarStyle{
return .lightContent
}
}
[あなたの質問を削除してから再投稿](http://stackoverflow.com/questions/44092723/issue-with-uiview)しないでください。 –
もう一度起こりません – HiDungLing