当用户滑动滚动时,是否有方法检测或获得通知



是否有一种方法来检测或获得通知,当用户滑动滚动?我正在使用(void)scrollViewDidScroll:(UIScrollView *) scrollView;但我得到错误:使用未声明的标识符'scrollViewDidScroll'有人能告诉我为什么吗?

@daf,H2SO3

 - (void)viewDidLoad
{
    [super viewDidLoad];
    // setting the color of this view
    self.view.backgroundColor = [UIColor whiteColor];
    //creating scrollview controller
    CGRect scrollViewFrame = [[UIScreen mainScreen]applicationFrame];
    scrollView = [[UIScrollView          alloc]initWithFrame:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y,self.view.frame.size.width,(self.view.frame.size.height)/3)];
    scrollView.contentSize = CGSizeMake(3200, 4000);
    scrollView.showsHorizontalScrollIndicator = YES;
    scrollView.showsVerticalScrollIndicator = YES;
    scrollView.backgroundColor = [UIColor grayColor];
    scrollView.delegate = self;
    scrollView.directionalLockEnabled = YES;
    [self.view addSubview:scrollView];
    //creating uiimage
    UIImage* image1 = [UIImage imageNamed:@"wallpapers1.jpg"];
    //creating image view
    UIImageView* imageView1 = [[UIImageView alloc]initWithImage:image1];
    imageView1.frame = CGRectMake(1241,0,image1.size.width,image1.size.height);
    [scrollView addSubview:imageView1];
    // [scrollView scrollRectToVisible:CGRectMake(1200, 0, 100, 100) animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
    ScrollDirection scrollDirection;
    if (self.lastContentOffset > scrollView.contentOffset.x)
        scrollDirection = ScrollDirectionRight;
    else if (self.lastContentOffset < scrollView.contentOffset.x)
        scrollDirection = ScrollDirectionLeft;
    self.lastContentOffset = scrollView.contentOffset.x;
    // do whatever you need to with scrollDirection here.
}

您正在使用错误的委托方法。试试用这个

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;

最新更新