OC 中 使用 swfit 代碼.
- Build Setings
- defines module 設置為 YES
- product module name 設置為項目工程名字(一般默認就是項目工程名字)
在需要用到 swift 文件的 類中 引入文件 ProjectName-Swift.h
文件
> ProjectName-Swift.h
文件 是系統創建的, 在工程中找不到, 有時候也不會自動提醒, 要完全自己手打完整個文件名字.
OC 項目中 在 oc 文件中 使用 swift 三方庫
要在 oc 項目中 引入文件
三方庫名-Swift.h
文件, 這個文件是系統自動生成的.
這樣就可以在 OC 文件中調用 swift 三方庫的方法了, 系統會自動把swift 方法映射為 oc 方法.
不過, 某些swift 特性不能轉化為 oc , 故 很多swift 方法不會映射為 oc 方法, 所以有一部分swfit方法 oc 文件不能使用
更多詳細介紹看兩篇文章
報錯:
The behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
The relevant UICollectionViewFlowLayout instance is <KanbanCollectionViewHorizontalLayout: 0x7fa39960c8e0>, and it is attached to <UICollectionView: 0x7fa39a8ba000; frame = (0 0; 375 70); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x60800064fba0>; layer = <CALayer: 0x608000230800>; contentOffset: {0, 0}; contentSize: {187.5, 70}> collection view layout: <KanbanCollectionViewHorizontalLayout: 0x7fa39960c8e0>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
- 在控制器中加上
self.automaticallyAdjustsScrollViewInsets = NO
當automaticallyAdjustsScrollViewInsets為YES時,它會找view里的scrollView,并設置scrollView的contentInset為{64, 0, 0, 0}。如果你不想讓scrollView的內容自動調整,將這個屬性設為NO(默認值YES)。
2.手動調整itemSize的大小
也有可能是, collectionView的itemSize 長或者寬 大于了 colloectionview. 調整一下就好了
現在正在看的文章: