我有一个包含WebView的自定义视图。我的自定义视图会在其中进行自己的布局,resizeWithOldSuperviewSize:
然后调用resizeSubviewsWithOldSize:
来调整其子视图的大小。
我的自定义视图包含一个WebView,一个NSTextField和另一个自定义视图。NSTextField和自定义视图对窗口大小的变化反应非常好,但是我的WebView只是停留在其原始大小。
编辑:请注意,WebView的位置按预期更改,但大小不会更改。
- (void)resizeSubviewsWithOldSize:(NSSize)oldSize
{
NSRect superBounds = self.superview.bounds;
// ... set frames on other subviews; works fine ...
// Move the WebView
NSRect oldFrame = webView.frame;
[self setNeedsDisplayInRect:oldFrame];
NSRect newFrame = NSMakeRect(superBounds.origin.x, 55.0, superBounds.size.width, superBounds.size.height - 55.0);
[webView setFrame:newFrame];
// This doesn't work:
// [[[[webView mainFrame] frameView] documentView] setNeedsDisplay:YES];
// Neither does this:
// [webView setNeedsDisplayInRect:newFrame];
}
有什么建议?
我可能已经解决了这个问题。关闭Interface Builder中的“自动布局”功能。我从不喜欢IB中的任何自动布局功能。我更喜欢在代码中进行自己的布局(更易于归档,查找,更改,复制等)。我已经在iOS上工作了一段时间,之前还没有遇到过自动版式。
因此,问题中引用的代码末尾的注释行都没有必要-只需设置框架即可。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句