UIView
は、UIViewController
の背景にグラデーションとして機能します。グラデーションコードはUIView
のdrawRect
です(下記参照)。そのグラディエントビューは、自動レイアウト(以下に示す制約)のあるUIViewController
ビューに接続されています。回転中の一貫した勾配を維持する
グラデーションはポートレートとランドスケープの両方で正しく表示されますが、の間には回転があり、白い背景が非常にはっきりと見えます(表示がコーナーで回転しているため)。
質問:回転中にどのように勾配を維持できますか?
グラデーションコード(私のサブクラス化UIView
中):問題は、この勾配にあなたの全体的なアプローチが間違っているということです
let gView = GradientView()
self.view.addSubview(gView)
gView.translatesAutoresizingMaskIntoConstraints = false
let gvCX = NSLayoutConstraint(item: gView, attribute: .CenterX, relatedBy: .Equal, toItem: self.view, attribute: .CenterX, multiplier: 1.0, constant: 0.0)
let gvCY = NSLayoutConstraint(item: gView, attribute: .CenterY, relatedBy: .Equal, toItem: self.view, attribute: .CenterY, multiplier: 1.0, constant: 0.0)
let gcH = NSLayoutConstraint(item: gView, attribute: .Height, relatedBy: .Equal, toItem: self.view, attribute: .Height, multiplier: 1.0, constant: 0.0)
let gcW = NSLayoutConstraint(item: gView, attribute: .Width, relatedBy: .Equal, toItem: self.view, attribute: .Width, multiplier: 1.0, constant: 0.0)
NSLayoutConstraint.activateConstraints([gvCX, gvCY, gvH, vW])