当用户滑动滚动时,有没有办法检测或获取通知? [关闭]
Posted
技术标签:
【中文标题】当用户滑动滚动时,有没有办法检测或获取通知? [关闭]【英文标题】:Is there a way to detect or get a notification when user swipes to scroll? [closed] 【发布时间】:2013-02-27 18:13:58 【问题描述】:有没有办法在用户滑动滚动时检测或获取通知? 我在用 (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.
【问题讨论】:
不,不是缺少任何代码。 发布更多代码让我们真正能够帮助您 设置点击手势识别器。 ***.com/questions/5216413/… 您在发布的代码中哪里得到错误? @STANGMMX 谢谢你的关心,但你能告诉我scrollViewDidScroll有什么问题吗? 【参考方案1】:您使用了错误的委托方法。试试这个
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
【讨论】:
我使用相同的委托方法 - (void)scrollViewDidScroll 这与发布的代码有何不同?参数名称可以是任何名称。以上是关于当用户滑动滚动时,有没有办法检测或获取通知? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
如何检测用户何时尝试滑动“过去的 UIScrollView 内容偏移”?