UIScrollview 動畫,setContentOffset:與setContentOffset:animate:異同點

一、
1.1使用animated參數(shù),可以獲得正確的UIScrollViewDelegate的回調(diào);而使用UIView動畫則不能。
scrollViewDidScroll:
scrollViewDidEndScrollingAnimation:

1.2不使用animated參數(shù),只可以回調(diào)scrollViewDidScroll:

二、
2.1使用animated參數(shù),可以獲取到動畫過程中contentOffset的值。
eg:
[scrollView setContentOffset:CGPointMake(0, 100) animated:YES];
NSLog(@"%f", scrollView.contentOffset.y);//輸出:0.000000
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
NSLog(@"%f", scrollView.contentOffset.y);//輸出:25.500000,每次輸出不保證一致
});
2.2不使用animated參數(shù),使用UIView動畫后,無論在什么時候查詢contentOffset的值,得到的都是動畫的最終值。
[UIView animateWithDuration:0.25
animations:^{
[scrollView setContentOffset:CGPointMake(0, 100)];
}];
NSLog(@"%f", scrollView.contentOffset.y);//輸出:100.000000

詳情見:http://ios.jobbole.com/85224/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容