iOS 9 View Not appearing

给你一囗甜甜゛ 提交于 2020-01-07 03:05:15

问题


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);

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.


回答1:


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



来源:https://stackoverflow.com/questions/32976447/ios-9-view-not-appearing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!