OC 中 使用 swfit 代碼.

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.

  1. 在控制器中加上
    self.automaticallyAdjustsScrollViewInsets = NO
    當automaticallyAdjustsScrollViewInsets為YES時,它會找view里的scrollView,并設置scrollView的contentInset為{64, 0, 0, 0}。如果你不想讓scrollView的內容自動調整,將這個屬性設為NO(默認值YES)。

2.手動調整itemSize的大小
也有可能是, collectionView的itemSize 長或者寬 大于了 colloectionview. 調整一下就好了

現在正在看的文章:

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 發現 關注 消息 iOS 第三方庫、插件、知名博客總結 作者大灰狼的小綿羊哥哥關注 2017.06.26 09:4...
    肇東周閱讀 12,250評論 4 61
  • 唯愿時光不在逼她,好姑娘永遠衣襟戴花
    ByJing鯨閱讀 185評論 1 1
  • 我與他真的好久不見,久到八、九年,久到聽說我們的同班小學同學有的已經當上父母,久到我們再也回不去那遙遠的小屁孩...
    阿拉米琪家閱讀 330評論 3 4