XYChatRoomScrollCollectionViewController.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // XYChatRoomScrollCollectionViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/6/28.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYChatRoomScrollCollectionViewController.h"
  9. @interface XYChatRoomScrollCollectionViewController ()
  10. @property (nonatomic,assign) CGFloat lastOffset;
  11. @end
  12. @implementation XYChatRoomScrollCollectionViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view.
  16. }
  17. - (void)setIsCloseScrollSwitch:(BOOL)isCloseScrollSwitch {
  18. _isCloseScrollSwitch = isCloseScrollSwitch;
  19. if (isCloseScrollSwitch) {
  20. self.canScroll = YES;
  21. }
  22. }
  23. - (void)setCanScroll:(BOOL)canScroll {
  24. _canScroll = canScroll;
  25. self.lastOffset = self.collectionView.contentOffset.y;
  26. }
  27. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  28. // NSLog(@"collectionView >>>>>>> 滚动 == %.2F",scrollView.contentOffset.y);
  29. if (self.isCloseScrollSwitch) {
  30. return;
  31. }
  32. if (!self.canScroll) {
  33. scrollView.contentOffset = CGPointZero;
  34. }
  35. if (scrollView.contentOffset.y < 0 ) {
  36. self.canScroll = NO;
  37. scrollView.contentOffset = CGPointZero;
  38. [[NSNotificationCenter defaultCenter] postNotificationName:@"chatroom_controller_leave_top" object:nil];//到顶通知父视图改变状态
  39. }
  40. scrollView.showsVerticalScrollIndicator = self.canScroll?YES:NO;
  41. }
  42. /*
  43. #pragma mark - Navigation
  44. // In a storyboard-based application, you will often want to do a little preparation before navigation
  45. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  46. // Get the new view controller using [segue destinationViewController].
  47. // Pass the selected object to the new view controller.
  48. }
  49. */
  50. @end