2017-05-04 72 views
-3

如何在swift中編寫下面的代碼。請幫忙。Swift中的自動調整

 UIView* destView = ((UIViewController *)segue.destinationViewController).view; 
     destView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     destView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 

謝謝!

回答

1

結帳以下代碼(SWIFT 3.1):

var destView: UIView? = (segue.destination as? UIViewController)?.view 
destView?.autoresizingMask = [.flexibleWidth, .flexibleHeight] 
destView?.frame = CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(view.frame.size.width), height: CGFloat(view.frame.size.height)) 
+0

Thankuuu這麼多 – Ren

+0

'讓destView = segue.destination.view'。沒有可選項,也不需要鑄造。 – Sulthan

+2

雖然你正確地翻譯了代碼。爲什麼不使用「destView?.frame = view.bounds」呢? – Lepidopteron