[英]iOS - Changing frame of a subview of a subclassed UIView (using storyboard with auto layout enabled)
[英]iOS:use the frame constrained by Auto Layout to create a subview
我使用IB和自動布局創建一個稱為boundView
視圖,然后在控制器中調用[self.boundView layoutIfNeeded]
,然后將self.boundView.frame.size
傳遞給一種方法,以生成boundView的子視圖CardView
的大小。 然后使用
PlayingCardView *playingCardView = [[PlayingCardView alloc]initWithFrame:frame];
以編程方式創建子視圖。 我確實使用NSLog來檢查子視圖的大小是否小於超級視圖。 但是當我使用[self.boundView addSubview:CardView]
添加子視圖時。 比superview大! 坐標有問題嗎?或者是因為我將自動版式與代碼創建的視圖結合在一起了?
你在哪兒 如果它在viewDidLoad
,則將尚未計算自動布局大小。 嘗試在viewDidLayoutSubviews
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.