2022年11月

CocoaPods 使用整理

CocoaPods 使用整理

指定源

CocoaPods支持私有 Spec 仓库的,我们可以建立自己的源,也可以使用非官方的源,只要是符合规定的都可以指定。

source 'https://github.com/artsy/Specs.git'  
source 'https://github.com/CocoaPods/Specs.git'

抑制警告

inhibit_warnings参数能够有效的抑制CocoaPods引入的第三方代码库产生的warning。

可以全部指定。

inhibit_all_warnings!

也可以针对指定。

pod 'ReactiveCocoa', '~> 2.4', :inhibit_warnings => true

使用git的HEAD指向的分支

pod 'ISO8601DateFormatter', :head

使用 master 分支

pod 'ARAnalytics/Mixpanel', :git => 'https://github.com/orta/ARAnalytics.git'

指定branch

pod 'Reachability', :git => 'https://github.com/ashfurrow/Reachability.git', :branch => 'frameworks'

指定tag

pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '0.7.0'

指定commit

pod 'ARTiledImageView', :git => 'https://github.com/dblockARTiledImageView', :commit => '1a31b864d1d56b1aaed0816c10bb55cf2e078bb8'

使用子库

可以这样

pod 'QueryKit/Attribute'

也可以这样指定多个子库

pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']

使用本地代码

通过:path可以指定本地代码,不过需要确保目录包含podspec文件。

pod 'AFNetworking', :path => '~/Documents/AFNetworking'

指定target的依赖库

target :ZipApp do  
  pod 'SSZipArchive'
end

排除taget

target 'Artsy Tests', :exclusive => true do  
  pod 'FBSnapshotTestCase', '1.4'
end

指定xcodeproj

默认会使用Podfile文件同级目录下第一个xcodeproj,但也可以指定

xcodeproj 'MyProject'
target :test do  
  # This Pods library links with a target in another project.
  xcodeproj 'TestProject'
end

指定连接的target

如果不显式指定连接的target,Pods会默认连接project的第一个target。如果需要,可以使用link_with指定连接一个或多个target

link_with 'MyApp', 'MyOtherApp'

指定依赖库的配置文件

pod 'PonyDebugger', :configuration => ['Release']

指定target的配置文件

xcodeproj 'TestProject', 'Mac App Store' => :release, 'Test' => :debug

使用Dynamic Frameworks代替Static Libraries

通过标志use_frameworks!就可知开启这个功能。如果需要使用Swift的库,就必须加上这个标志了。

加快pod install/update 速度

使用CocoaPods来添加第三方类库,无论是执行pod install还是pod updat很多时候都卡在了Analyzing dependencies不动,这是更新本地的pod spec所以文件导致的。通过–no-repo-update标志可以不更新本地pod spec索引。当然首次install不应该添加这个标志,后续修改Podfile的时候可以适当使用,加快pod速度。

pod install --no-repo-update  
pod update --no-repo-update

输出详细日志

pod update --verbose

Link:

Flutter GestureDetector 点击空白区域无反应解决办法

在flutter中只用GestureDetector添加点击事件,发现在空白区域点击无效,事件不响应。解决办法:

GestureDetector(
    behavior: HitTestBehavior.opaque,
)

说明:

/// How to behave during hit tests.
enum HitTestBehavior {
  /// Targets that defer to their children receive events within their bounds
  /// only if one of their children is hit by the hit test.
  deferToChild,

  /// Opaque targets can be hit by hit tests, causing them to both receive
  /// events within their bounds and prevent targets visually behind them from
  /// also receiving events.
  opaque,

  /// Translucent targets both receive events within their bounds and permit
  /// targets visually behind them to also receive events.
  translucent,
}

翻译一下就是:

当behavior选择 deferToChild 时,只有当前容器中的child被点击时才会响应点击事件

当behavior选择 opaque 时,点击整个区域都会响应点击事件,但是点击事件不可穿透向下传递,注释翻译:阻止视觉上位于其后方的目标接收事件,所以我需要的这种效果直接将behavior设置为HitTestBehavior.opaque就可以了;

当behavior选择 translucent 时,同样是点击整个区域都会响应点击事件,和opaque的区别是点击事件是否可以向下传递,注释翻译:半透明目标既可以在其范围内接受事件,也可以允许视觉上位于其后方的目标接收事件

Link: