masonry库最低支持版本引起的崩溃问题

问题及解决

  • 问题
    开发中,遇到在代码中使用mas_bottomMargin崩溃的问题。
  • 解决方法
    修改Masonry Target最低支持版本为iOS8.0以上


    三方库Target最低版本.png

原因分析及进一步优化处理

  • 原因
    mas_bottomMargin等几个属性定义依靠的是最低支持版本至少是8.0。
#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)

@property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_rightMargin;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_topMargin;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomMargin;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_leadingMargin;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_trailingMargin;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins;
@property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins;

#endif
  • 优化处理
    为了防止其它Pod安装的三方库遇到类似问题,可以在Podfifle文件最后统一修改为三方库最低支持iOS版本与app保持一致, 比如app最低支持iOS9.0的写法如下
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
    end
  end
end

参考

# Set deployment target for CocoaPods's pod

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容