I created a UIView programatically and add NSLayoutConstraint to it and it works and then add it as a subView of view controller's view. Right now I need to remove this view from superview and some time later add it again. But the layout won't work any more if I add it again using self.view addSubview
. How to make the layout works again?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
The problem is the sub view does not inherit the original view's size/frame, and there for adds the view as if it was stuck in the Any+Any size of 600x600. My solution, is to set the frame of the original view, and then let iOS do the remainder of the work.
When you create constraints assign it to variables
When you want to remove it from the superview remove the constraints
Remove your view and again while adding assign the constraint as
You need to take care of some points while adding and removing views from auto layout.
There are two methods available in
UIView.h
classUse these methods as per your requirement. So i suggest when ever you remove subview from view, Update constraint of superior view if it is required. And then call below method to reflect layout changes.
Most cases above method will solve all layout related issues. However some time if complex structure is there i mean runtime changing behaviour of views.
Then override below method in your
UIViewController
, Perform all frame related changes in this method.