繁体   English   中英

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

[英]How to add subview from xib file in ios 9?

我有一个老项目,因为用户将其操作系统更新为ios 9.0,因此面临错误。 关键是我的视图已加载,所有按钮和功能都正常运行,但是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];

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

我认为添加子视图没有任何区别。 您可以尝试类似...

  • 注释该行self.theScrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
  • @property (weak, nonatomic) IBOutlet UIView *mainToolbar2;弱变为强@property (weak, nonatomic) IBOutlet UIView *mainToolbar2;

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM