iOS 9视图未出现 [英] iOS 9 View Not appearing

查看:63
本文介绍了iOS 9视图未出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,在iOS 9中运行时,我的应用程序中未显示uibutton(在较早的OS版本中可以正常运行).我知道有些人注意到情节提要有类似的问题( https://forums.developer.apple.com/线程/14003 ),尽管我没有使用这些,而是​​以编程方式构建了我的视图.无需担心自动布局或自动调整大小的蒙版.

I have noticed a that a uibutton is not showing in my app when run in iOS 9 (works fine in earlier OS versions). I know several have noticed a similar issue with storyboards (https://forums.developer.apple.com/thread/14003), though I am not using those and am instead building my view programmatically. There is no autolayout or autoresizingmask to worry about.

UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(SUG_MARGIN, self.mainView.bounds.size.height - 40 - margin, self.mainView.bounds.size.width-margin*2, 40);
[button setTitle:NSLocalizedString(@"...", nil) forState:UIControlStateNormal];
button.titleLabel.font = //...;
button.backgroundColor = //...;
[self.mainView addSubview:button];

NSLog(@"main:%@\nadd:%@\nsuper:%@", NSStringFromCGRect(self.mainView.frame), NSStringFromCGRect(button.frame), button.superview);

该nslog显示正确设置的所有内容.

That nslog shows everything set up correctly.

我在整个应用程序上都有类似的按钮,但这是唯一没有出现的按钮,这就是为什么我要挠头.

I have similar buttons all over the app, but this is the only one that is not appearing, which is why I am scratching my head.

推荐答案

重构后的代码仅在viewWillLayoutSubviews中分配度量帧,并且现在可以使用.

Refactored code to assign only measure frames in viewWillLayoutSubviews and it now works. strange.

这篇关于iOS 9视图未出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆