【问题标题】:How to add subview from xib file in ios 9?如何在 ios 9 中从 xib 文件添加子视图?
【发布时间】:2016-08-01 21:40:20
【问题描述】:

自从用户将他们的操作系统更新到 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 上运行?

【问题讨论】:

    标签: ios ipad uiview ios9 addsubview


    【解决方案1】:

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

    • 评论self.theScrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    • @property (weak, nonatomic) IBOutlet UIView *mainToolbar2; 行中将弱变为强

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-20
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2014-01-20
      相关资源
      最近更新 更多