iOS开发常见问题
1. 在 ViewController 中添加子视图时,导航栏遮挡添加的子视图
let bpView = BpView.init(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)) self.view.addSubview(bpView)
以上代码在 viewDidLoad 添加时视图会被遮挡,解决遮挡问题,我们只需要在 viewDidLoad 开始出添加如下代码即可解决:
self.edgesForExtendedLayout = UIRectEdge.init(rawValue: 0)
2.iphone X屏幕适配问题
1 | 获取状态栏大小 |
CGRect statusRect = [[UIApplication sharedApplication] statusBarFrame];
1 | 获取导航栏大小 |
CGRect navRect = self.navigationController.navigationBar.frame;
3.在实现模态弹出框的时候,一定要设置ViewController的类型和转换代理,否则弹出时大小不正确
self.connectingAlertController.modalPresentationStyle = UIModalPresentationCustom;
self.connectingAlertController.transitioningDelegate = self;
4.CocoaPods删除第三方库
在Podfile里面删除对应库后执行以下命令
pod install --verbose --no-repo-update
5.在ViewDidLoad中获取到的视图大小不是最终的
由于存在约束,自动布局,在ViewDidLoad执行时,视图还未准备就绪,所以在此时获取到有关视图大小的数据是不准确的
6.UIScrollView子视图添加约束问题
有关约束的几个知识点:
约束包含距离约束、宽高和居中,约束一般都是以内容视图为参考依据,普通的View的frame和内容视图的大小相同,所以在添加约束的时候不会出现问题;而UIScrollView的内容视图是根据子视图的大小计算出来的,所以在添加的子视图的大小要能够确定,不管是直接指定还是根据约束计算出来的
7.代码添加约束
需要设置视图的 translatesAutoresizingMaskIntoConstraints 为 NO
8.可视化添加UIButton时,type要选择Custom,否则,设置背景图片的时候左上角可能会有色块
9.浮点数处理类:NSDecimalNumber NSDecimalNumberHandler
10.设置导航栏标题颜色 [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
11.pod 常用命令
pod install --- 重新安装 Podfile 引用的库
pod repo update --- 更新库
pod install --verbose --no-repo-update --- 安装新增库,不更新已存在库
pod install 库名 --- 安装指定名称的库
12. 获取 UiTableViewCell 子视图大小
暂没有解决办法
13. 使用定时器更新 cell 内容导致以下警告信息
[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <UITableView: 0x13b017a00; frame = (0 96; 414 717); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x280a1ea90>; layer = <CALayer: 0x280466100>; contentOffset: {0, 0}; contentSize: {414, 160}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <.DeviceListViewController: 0x13883dc00>>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端