OC 中 使用 swfit 代碼.
- Build Setings
- defines module 設(shè)置為 YES
- product module name 設(shè)置為項(xiàng)目工程名字(一般默認(rèn)就是項(xiàng)目工程名字)
在需要用到 swift 文件的 類中 引入文件 ProjectName-Swift.h
文件
> ProjectName-Swift.h
文件 是系統(tǒng)創(chuàng)建的, 在工程中找不到, 有時(shí)候也不會(huì)自動(dòng)提醒, 要完全自己手打完整個(gè)文件名字.
OC 項(xiàng)目中 在 oc 文件中 使用 swift 三方庫(kù)
要在 oc 項(xiàng)目中 引入文件
三方庫(kù)名-Swift.h
文件, 這個(gè)文件是系統(tǒng)自動(dòng)生成的.
這樣就可以在 OC 文件中調(diào)用 swift 三方庫(kù)的方法了, 系統(tǒng)會(huì)自動(dòng)把swift 方法映射為 oc 方法.
不過(guò), 某些swift 特性不能轉(zhuǎn)化為 oc , 故 很多swift 方法不會(huì)映射為 oc 方法, 所以有一部分swfit方法 oc 文件不能使用
更多詳細(xì)介紹看兩篇文章
報(bào)錯(cuò):
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
當(dāng)automaticallyAdjustsScrollViewInsets為YES時(shí),它會(huì)找view里的scrollView,并設(shè)置scrollView的contentInset為{64, 0, 0, 0}。如果你不想讓scrollView的內(nèi)容自動(dòng)調(diào)整,將這個(gè)屬性設(shè)為NO(默認(rèn)值YES)。
2.手動(dòng)調(diào)整itemSize的大小
也有可能是, collectionView的itemSize 長(zhǎng)或者寬 大于了 colloectionview. 調(diào)整一下就好了
現(xiàn)在正在看的文章: