資源描述:
《[無限互聯(lián)]ios開發(fā)之框架hgpagescrollview淺談》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫。
1、框架HGPageScrollView實(shí)現(xiàn)了類UICollectionView的功能,橫向滑動(dòng)瀏覽。分兩個(gè)模式甲板模式和單頁模式,能添加刪除頁面。demo效果圖:甲板模式:單頁模式:deckMode按鈕:在兩個(gè)模式間切換add按鈕:增加頁面remove按鈕:刪除頁面只能在甲板模式下才能實(shí)現(xiàn)增加,刪除功能。代碼封裝運(yùn)用和UITableView一樣實(shí)現(xiàn)HGPageScrollView的datasource協(xié)議方法自定義pageView類,相當(dāng)于自定義cellpageData對(duì)應(yīng)pageView的model,給pageView填充上數(shù)據(jù)[objc]?viewplaincopyprint?
2、1.#pragma?mark?-?HGPageScrollView?datasource??2.//設(shè)置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復(fù)用??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.????//設(shè)置page高度??22.????CGRect?frame?=?pageView.frame;??23.????frame.size.height?=?420;??24
5、.????pageView.frame?=?frame;??25.????return?pageView;??26.??????27.}??28.??29.//設(shè)置HGPageScrollView的標(biāo)題??30.-?(NSString?*)pageScrollView:(HGPageScrollView?*)scrollView?titleForPageAtIndex:(NSInteger)index;??31.{??32.????MyPageData?*pageData?=?[_myPageDataArray?objectAtIndex:index];??33.????retur
6、n?pageData.title;??34.}??35.??1.//設(shè)置HGPageScrollView的子標(biāo)題??2.-?(NSString?*)pageScrollView:(HGPageScrollView?*)scrollView?subtitleForPageAtIndex:(NSInteger)index;??3.{??4.????MyPageData?*pageData?=?[_myPageDataArray?objectAtIndex:index];??5.????return?pageData.subtitle;??6.}??實(shí)現(xiàn)HGPageScrollView的
7、delegate協(xié)議方法當(dāng)處于甲板模式,選中page后,切換到單頁模式,重新布局page頁面[objc]?viewplaincopyprint?1.#pragma?mark?-?HGPageScrollView?delegate??2.//選中page觸發(fā)的協(xié)議方法??3.-?(void)pageScrollView:(HGPageScrollView?*)scrollView?didSelectPageAtIndex:(NSInteger)index?{??4.??