【问题标题】:How to apply autolayout NIB instance within UIView subviews如何在 UIView 子视图中应用自动布局 NIB 实例
【发布时间】:2015-11-30 20:54:52
【问题描述】:

我有一个 UIViewController 实例,名为:MainController。在这个 MainController.view 中,我有另一个视图(类名为 SlideViewContent),它有一个 nib 实例:

NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"SlideMenuView"
                                                     owner:self
                                                   options:nil];
self.bottomSlideMenu = [nibContents objectAtIndex:0];
self.bottomSlideMenu.frame = CGRectMake(0,0,screenWidth,screenHeight);
self.bottomSlideMenu.bounds = CGRectMake(0,0,screenWidth,screenHeight);

所有自动布局约束都已添加到 nibFile 中,并且可以正常工作,没有任何警告。我想对此应用自动布局并调用这些方法来刷新具有良好屏幕尺寸的 UI:

[self setNeedsDisplay] or [self setNeedsLayout];

但是什么都行不通!

【问题讨论】:

  • [self layoutIfNeeded] 怎么样?

标签: ios objective-c uiview nib


【解决方案1】:

不需要实现 [self setNeedsDisplay] 或 [self setNeedsLayout];

只需实现 layoutSubviews 并设置视图的框架。

- (void)layoutSubviews
{  
    CGRect screenBound = [[UIScreen mainScreen] bounds];
    CGSize screenSize = screenBound.size;
    CGFloat screenWidth = screenSize.width;
    CGFloat screenHeight = screenSize.height;

    self.bottomSlideMenu.frame = CGRectMake(0,0,screenWidth,screenHeight);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多