ios開發經常會用到uiscrollview,而能夠平滑的展示划動效果,是至關重要的。但,經常會在划動到中間位置的時候,出現卡頓,很影響使用者體驗性。因此,個人把個人的一些經驗整理下,用**說話,一目了然。
1、建立uiscrollview和三個自定義的view:
scrollview = [[uiscrollview alloc] initwithframe:cgrectmake(0, 54, top_big_image_width, top_big_image_height)];
scrollview.autoresizingmask = uiviewautoresizingflexiblewidth;
"white-space:pre"> self.scrollview.contentsize = cgsizemake(numberofpages * self.scrollview.frame.size.width,
self.scrollview.frame.size.height);
self.scrollview.delegate = self;
scrollview.autoresizessubviews = yes;
scrollview.pagingenabled = yes;
scrollview.showshorizontalscrollindicator = no;
scrollview.scrollstotop = no;
[selfview addsubview:scrollview];
三個自定義view。函式setpagecontentwithpageview:(customview *)pageview withpagenumber:(nsinteger)pagenumber,是對customview進行更新操作的**。
view plain
print?
prevpageview = [[customview alloc] initwithframe:cgrectmake(0, 0, self.scrollview.frame.size.width,
self.scrollview.frame.size.height)];
currentpageview = [[customview alloc] initwithframe:cgrectmake(0, 0, self.scrollview.frame.size.width,
self.scrollview.frame.size.height)];
nextpageview = [[customview alloc] initwithframe:cgrectmake(0, 0, self.scrollview.frame.size.width,
self.scrollview.frame.size.height)];
cgfloat pagewidth = self.scrollview.frame.size.width;
cgfloat pageheight = self.scrollview.frame.size.height;
currentpageview.frame = cgrectmake(currentpage * pagewidth, 0, pagewidth, pageheight);
[self setpagecontentwithpageview:currentpageview withpagenumber:currentpage];
//第一頁
if (currentpage == 0)
} //最後一頁
else
if (currentpage == numberofpages - 1)
else
[self.scrollview addsubview:currentpageview];
[self.scrollview addsubview:prevpageview];
[self.scrollview addsubview:nextpageview];
oint offset = cgpointmake(currentpage * self.scrollview.frame.size.width, 0);
[self.scrollview setcontentoffset:offset animated:no];
2、在- (void)scrollviewdidscroll:(uiscrollview *)sender方法中進行頁面更新。
view plain
print?
#pragma mark -
#pragma mark uiscrollviewdelegate methods
- (void)scrollviewdidscroll:(uiscrollview *)sender
else
} 函式refreshpageviewafterpaged是頁面的更新操作判斷。
view plain
print?
- (void)refreshpageviewafterpaged:(nsnumber *)prevpagenumber
else
} else
if (currentpage + 1 == prevpage)
else
} [pool release];
}
UIScrollView 平滑划動處理
ios開發經常會用到uiscrollview,而能夠平滑的展示划動效果,是至關重要的。比較常用的方法有兩種 1 將所有的scrollview子頁面都add到scrollview中,這樣可以平滑滑動,但占用資源加多,並且初始化載入比較慢。2 使用三個頁面view,在滑動過程中如指標輪詢那樣交替使用。優...
UIScrollView 平滑划動處理
ios開發經常會用到uiscrollview,而能夠平滑的展示划動效果,是至關重要的。比較常用的方法有兩種 1 將所有的scrollview子頁面都add到scrollview中,這樣可以平滑滑動,但占用資源加多,並且初始化載入比較慢。2 使用三個頁面view,在滑動過程中如指標輪詢那樣交替使用。優...
UIScrollView實現重用
import inte ce test19viewcell uiview 索引 property nonatomic,assign nsuinteger index 文字 property nonatomic,copy nsstring text 文字控制項 property nonatomic,r...