当用户滑动滚动时,有没有办法检测或获取通知? 我在用 (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.
}
答案 0 :(得分:-1)
您使用的是错误的委托方法。尝试使用这个
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;