Search code examples
objective-clayoutxibuiwindowsize-classes

UIView with xib ignores size classes


I'm working on custom notification view, which must show up over everything. To achive this I've implemented it as a subview of separate UIWindow and everything works fine except for layout: I use size classes, and layout just ignores it. Here is the code I use to setup my view:

NotificationView *notificationView = [[[NSBundle mainBundle] loadNibNamed:@"NotificationView"
                                                                    owner:self
                                                                  options:nil] firstObject];
UIWindow *window = [[UIWindow alloc] initWithFrame:frame];
// Additional window setup..

[window addSubview:notificationView];

Solution

  • UPD: I figured it out

    I was adding my notificationView to UIWindow directly, in this case size classes get ignored. Then I tried to instantiate corresponding UIViewController subclass (though I don't really need it) and add it to its self.view in this case size classes work as expected.

    Conclusion: View must be in UIViewController view hierarchy to support size classes.