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屏幕适配问题

获取状态栏大小
CGRect statusRect = [[UIApplication sharedApplication] statusBarFrame];
获取导航栏大小
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>>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值