資源描述:
《[無限互聯(lián)]ios開發(fā)之框架hgpagescrollview淺談》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在應用文檔-天天文庫。
1、框架HGPageScrollView實現(xiàn)了類UICollectionView的功能,橫向滑動瀏覽。分兩個模式甲板模式和單頁模式,能添加刪除頁面。demo效果圖:甲板模式:單頁模式:deckMode按鈕:在兩個模式間切換add按鈕:增加頁面remove按鈕:刪除頁面只能在甲板模式下才能實現(xiàn)增加,刪除功能。代碼封裝運用和UITableView一樣實現(xiàn)HGPageScrollView的datasource協(xié)議方法自定義pageView類,相當于自定義cellpageData對應pageView的model,給pageView填充上數(shù)據(jù)[objc]?viewplaincopyprint?
2、1.#pragma?mark?-?HGPageScrollView?datasource??2.//設置page的數(shù)量??3.-?(NSInteger)numberOfPagesInScrollView:(HGPageScrollView?*)scrollView?{??4.????return?_myPageDataArray.count;??5.}??6.??7.//創(chuàng)建page??8.-?(HGPageView?*)pageScrollView:(HGPageScrollView?*)scrollView?viewForPageAtIndex:(NSInteger)index
3、?{??9.??????10.????//page復用??11.????static?NSString?*pageId?=?@"pageId";??12.????MyPageView?*pageView?=?(MyPageView*)[scrollView?dequeueReusablePageWithIdentifier:pageId];??13.????if?(!pageView)?{??14.????????pageView?=?[[[NSBundle?mainBundle]?loadNibNamed:@"MyPageView"?owner:self?options:nil]
4、?lastObject];??15.????????pageView.reuseIdentifier?=?pageId;??16.????}??17.??????18.????MyPageData?*pageData?=?[_myPageDataArray?objectAtIndex:index];??19.????pageView.myPageData?=?pageData;??20.??????21.????//設置page高度??22.????CGRect?frame?=?pageView.frame;??23.????frame.size.height?=?420;??24
5、.????pageView.frame?=?frame;??25.????return?pageView;??26.??????27.}??28.??29.//設置HGPageScrollView的標題??30.-?(NSString?*)pageScrollView:(HGPageScrollView?*)scrollView?titleForPageAtIndex:(NSInteger)index;??31.{??32.????MyPageData?*pageData?=?[_myPageDataArray?objectAtIndex:index];??33.????retur
6、n?pageData.title;??34.}??35.??1.//設置HGPageScrollView的子標題??2.-?(NSString?*)pageScrollView:(HGPageScrollView?*)scrollView?subtitleForPageAtIndex:(NSInteger)index;??3.{??4.????MyPageData?*pageData?=?[_myPageDataArray?objectAtIndex:index];??5.????return?pageData.subtitle;??6.}??實現(xiàn)HGPageScrollView的
7、delegate協(xié)議方法當處于甲板模式,選中page后,切換到單頁模式,重新布局page頁面[objc]?viewplaincopyprint?1.#pragma?mark?-?HGPageScrollView?delegate??2.//選中page觸發(fā)的協(xié)議方法??3.-?(void)pageScrollView:(HGPageScrollView?*)scrollView?didSelectPageAtIndex:(NSInteger)index?{??4.??