如何在ios 9中从xib文件添加子视图?

如何在ios 9中从xib文件添加子视图?,ios,ipad,uiview,ios9,addsubview,Ios,Ipad,Uiview,Ios9,Addsubview,我有一个老项目,自从用户将他们的操作系统升级到ios 9.0后,它就面临着一个bug。问题是我的视图已经加载,所有的按钮和功能都很好地工作,但是ui只是空白 这是我在ios 8.1上运行的应用程序的屏幕截图 这是我在ios 9.1上运行的应用程序 这是我的代码: 我的viewcontroller.h文件: @property (strong, nonatomic) IBOutlet UIScrollView *theScrollView; @property (weak, nonatomic

我有一个老项目,自从用户将他们的操作系统升级到ios 9.0后,它就面临着一个bug。问题是我的视图已经加载,所有的按钮和功能都很好地工作,但是ui只是空白

这是我在ios 8.1上运行的应用程序的屏幕截图

这是我在ios 9.1上运行的应用程序

这是我的代码:

我的viewcontroller.h文件:

@property (strong, nonatomic) IBOutlet UIScrollView *theScrollView;
@property (weak, nonatomic) IBOutlet UIView *mainToolbar2;
我的viewcontroller.m:

CGRect scrollViewRect = CGRectInset(viewRect, -scrollViewOutset, 0.0f);
self.theScrollView = [[UIScrollView alloc] initWithFrame:scrollViewRect]; // All
self.theScrollView.autoresizesSubviews = NO;
self.theScrollView.contentMode = UIViewContentModeRedraw;
self.theScrollView.showsHorizontalScrollIndicator = NO;
self.theScrollView.showsVerticalScrollIndicator = NO;
self.theScrollView.scrollsToTop = NO;
self.theScrollView.delaysContentTouches = NO;
self.theScrollView.pagingEnabled = YES;
self.theScrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.theScrollView.backgroundColor = [UIColor redColor];
self.theScrollView.delegate = self;

if (_isArabic) {
    self.theScrollView.transform=CGAffineTransformMakeRotation(M_PI * (180) / 180.0);
}

[self.mainView addSubview:self.theScrollView];

CGRect toolbarRect = viewRect;
toolbarRect.size.height = TOOLBAR_HEIGHT;
self.mainToolbar = [[ReaderMainToolbar alloc] initWithFrame:toolbarRect document:document]; // ReaderMainToolbar
self.mainToolbar.delegate = self; // ReaderMainToolbarDelegate
[self.mainView addSubview:self.mainToolbar];

if (fakeStatusBar != nil) [self.mainView addSubview:fakeStatusBar]; // Add status bar background view

for (UIView *subView in self.mainToolbar.subviews)
{
    [subView removeFromSuperview];
}

[self.mainToolbar addSubview:self.mainToolbar2];

我认为在iOS9上有一些我不知道的从xib文件添加子视图的变化。如何解决此问题,使应用程序也可以在ios 9上运行?

我认为添加子视图没有任何区别。你可以试试像

  • 注释行
    self.theScrollView.autoresizingMask=(UIViewAutoresizingFlexibleWidth | UIViewAutoResizingFlexibleHight);
    
  • 将行
    @属性(弱,非原子)IBUIView*mainToolbar2中的弱更改为强