简体   繁体   English

当其父视图更改大小时,如何告诉子视图调整大小?

[英]How can I tell a subview to resize when its superview changes size?

I'm working on an iOS application that has a UIViewController whose view has a MapView as a subview. 我正在使用具有UIViewController的iOS应用程序,该UIViewController的视图具有MapView作为子视图。 However, when I run the application and try to rotate the view in the simulator, it doesn't work as it should; 但是,当我运行该应用程序并尝试在模拟器中旋转视图时,它无法正常工作; it leaves a black box as shown: 它留下一个黑框,如下所示:

原始视图

旋转视图

How can I tell the MapView to resize along with its superview? 如何告诉MapView调整其超级视图的大小?

Try to use this code 尝试使用此代码

ObjC 对象

yourMapView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
                               UIViewAutoresizingFlexibleLeftMargin |
                               UIViewAutoresizingFlexibleBottomMargin;

Swift 迅速

yourMapView.autoresizingMask = [.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使超级视图自动调整大小并与其子视图保持一致? - How to make a superview resize automatically same size and coordinate with its subview? 当另一个子视图改变位置时如何调整子视图的大小 - How to resize a subview when another subview changes its position Subview 不会随着 superView 的大小变化而调整大小 - Subview is not resizing with the size changes of superView 移动子视图时,如何在其超视图中将其子视图保留在同一位置? - When moving a subview around, how do I keep a subview of it in the same place in its superview? 子视图的大小不等于其父视图 - Subview's size not equal to its superview 当我的 UITableViewCell 的内容发生变化时,如何告诉它“自动调整大小”? - How do I tell my UITableViewCell to “auto-resize” when its content changes? 当用户在iPhone中触摸其子视图时,如何实现关闭子视图? - How to implement close a subview when user touched its superview in iphone? 如何使我的超级视图调整大小,以使其子视图的大小与Autolayout相匹配? - How do I make my superview resize to match the size of its subviews with Autolayout? 无法从其子视图中删除子视图 - Can't remove a subview from its superview 如何从超级视图的超级视图中将subView置于顶部 - How to bring subView to top from superview of its superview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM