ios UICollectionView滑動時操作

來源:互聯網
上載者:User

標籤:style   blog   io   color   os   使用   sp   div   on   

點開UICollectionViewDelegate,發現有@protocol UICollectionViewDelegate <UIScrollViewDelegate>。

所以只要實現UIScrollViewDelegate的

- (void)scrollViewDidScroll:(UIScrollView *)scrollView; 方法,就可以重寫UICollectionView滑動操作

例如,在UICollection上方有一個名為testImg的ImageView,要跟著UICollection的滑動一起動,那麼可以使用下面方法

 1 - (void)scrollViewDidScroll:(UIScrollView *)scrollView 2 { 3     CGPoint point=scrollView.contentOffset; 4     NSLog(@"%f,%f",point.x,point.y); 5      6     CGRect frame = [_testImg frame]; 7     frame.origin.y = 43-point.y; 8     _testImg.frame = frame; 9     10     frame = [scrollView frame];11     frame.origin.y = 179-point.y;12     scrollView.frame = frame;13 }

需要注意的是,第7行的43和第11行的179分別為testImg和UICollectionView初始的y軸值,不是滑動之前的值。如果使用

控制項.origin.y -= point.y;

y值就會快速變小,控制項瞬間飛出螢幕

上述代碼中,point是滑動之後的位移量,手指上滑,位移y為正

ios UICollectionView滑動時操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.