0
我有一個uiscrollview。 ScrollView包含多個uiview作爲子視圖。我希望像動畫效果一樣將頁面分頁。我已經設置scrollview.pagingEnabled = NO。UIScrollview與分頁像效果
以下是我的代碼
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
lastContentOffset = scrollView.contentOffset.x;
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
ScrollDirection scrollDirection;
if (self.lastContentOffset >scrollView.contentOffset.x) {
scrollDirection = ScrollDirectionRight; } else if (self.lastContentOffset < scrollView.contentOffset.x) {
scrollDirection = ScrollDirectionLeft;
}
if (scrollDirection==ScrollDirectionRight) {
CGFloat xOffset = scrollview.contentOffset.x;
CGFloat yOffset = scrollview.contentOffset.y;
if (scrollview.contentOffset.x != scrollview.frame.origin.x)
{
[scrollview setContentOffset:CGPointMake(xOffset- 320, yOffset) animated:YES];
}
NSLog(@" ScrollDirectionRight custom x==%f %f", scrollview.contentOffset.x, scrollview.contentSize.width);
} else if(scrollDirection==ScrollDirectionLeft) {
CGFloat xOffset = scrollview.contentOffset.x;
CGFloat yOffset = scrollview.contentOffset.y;
if ((scrollview.contentOffset.x != scrollview.frame.origin.x))
{
[scrollview setContentOffset:CGPointMake(xOffset + 320, yOffset) animated:YES];
}
NSLog(@"ScrollDirectionLeft custom x==%f %f", scrollview.contentOffset.x, scrollview.contentSize.width);
}
}
通過這個代碼即時得到尋呼像effect.but效果並不順利。
感謝
你想要什麼樣的動畫? – danypata
每當我滾動下一個視圖應該在中心 – user2185354