我已经将UITableView(作为KRTableView)子类化并实现了四种基于触摸的方法(touchesBegan,touchesEnded,touchesMoved和touchesCancelled),以便我可以检测何时在UITableView上处理基于触摸的事件.基本上我需要检测的是当UITableView向上或向下滚动时.
但是,子类化UITableView并创建上述方法只能检测UITableViewCell内的滚动或手指移动,而不是整个UITableView.
一旦我的手指移动到下一个单元格,触摸事件就不会做任何事情.
这就是我为UITableView创建子类的方法:
#import "KRTableView.h"
@implementation KRTableView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
NSLog(@"touches began...");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
NSLog(@"touchesMoved occured");
}
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent *)event {
[super touchesCancelled:touches withEvent:event];
NSLog(@"touchesCancelled occured");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
NSLog(@"A tap was detected on KRTableView");
}
@end
Run Code Online (Sandbox Code Playgroud)
如何检测UITableView何时向上或向下滚动?
我做了足够的google,并且在发布之前我确实在stackoverflow中检查了这些帖子(在UIScrollView中查找滚动的方向?).我在iPhone应用程序中拥有动态数量的照片,正在显示UIScrollView.在任何时候,我只在滚动视图中显示3张照片.当我有4张照片时,总计:第1张照片:偏移量0.0显示第2张照片:偏移量320.0显示第3张照片:显示偏移量640.0
现在,当用户滚动到第4张照片时,滚动视图将重置为0.0偏移.如果用户试图滚动"超出"第4张照片,则滚动应仅在右向停止(因此用户不会滚动"超出").但是目前,用户'能够'滚动到最后一张照片之外; 但是,我以编程方式检测到此并重置偏移量.但它看起来并不整洁,因为用户会瞬间看到黑色背景.我想检测用户是否已经开始向右滚动(请记住,向左滚动'即'前一张'照片就可以了)scrollViewWillBeginDragging,以便我可以停止向右滚动.
我尝试了什么:
self.scrollView.panGestureRecognizer's
translationInView是行不通的,因为首先没有
panGestureRecognizer返回实例(!),尽管UIScrollView API声称如此.scrollViewDidEndDecelerating是可能的,虽然它不符合我的目的.我正在学习如何使用TableViews,我想知道如何判断tableView是向上还是向下滚动?我一直在尝试各种各样的事情,但是它没有被授予,下面是滚动视图,我有一个TableView.任何建议都会很棒,因为我是新手......
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
if scrollView.panGestureRecognizer.translation(in: scrollView).y < 0 {
print("down")
} else {
print("up")
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在tableView代码中的内容
func tableView(_ tableView:UITableView, numberOfRowsInSection section:Int) -> Int {
return Locations.count
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == self.Posts.count - 4 {
reloadTable(latmin: self.latmin,latmax: self.latmax,lonmin: self.lonmin,lonmax: self.lonmax,my_id: myID)
print("Load More")
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "HomePageTVC", for: indexPath) as! NewCell
cell.post.text = Posts[indexPath.row] …Run Code Online (Sandbox Code Playgroud) 我有一个collectionView.我想检测滚动方向.我有两种不同的动画风格,可以向下滚动并向上滚动.所以我必须学习滚动方向.
CGPoint scrollVelocity = [self.collectionView.panGestureRecognizer
velocityInView:self.collectionView.superview];
if (scrollVelocity.y > 0.0f)
NSLog(@"scroll up");
else if(scrollVelocity.y < 0.0f)
NSLog(@"scroll down");
Run Code Online (Sandbox Code Playgroud)
这只是触摸手指的工作.不适合我
objective-c uigesturerecognizer ios uipangesturerecognizer uicollectionview
我需要在iOS tableview中实现像google这样的横向分页.我们有什么方法可以使用单个tableview来做到这一点吗?你能建议一种方法吗?
我想复制在Pinterest应用程序中看到的效果,它们根据滚动方向隐藏顶部和底部条形图.我的问题是:确定UIScrollView滚动方式的正确方法是什么?
我正在尝试实现scrollViewWillBeginDragging方法. 当调用此方法时,我检查用户是否已选择滚动视图中的一个按钮处于状态:selected.如果没有,那么我显示UIAlert以通知用户.
我的问题是,如果用户从右向左滚动(从右侧拉下一个视图),我只想调用按钮选择(NextQuestion)方法.但是,如果他们从左向右滚动,那么我希望它像往常一样滚动.
目前无论用户在哪个方向滚动,都会调用检查器方法.如何在从右向左滚动时调用方法?
以下是我目前的实现方式:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self NextQuestion:scrollView];
}
-(IBAction)NextQuestion:(id)sender
{
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth) / pageWidth) + 1;
NSInteger npage = 0;
CGRect frame = scrollView.frame;
// Check to see if the question has been answered. Call method from another class.
if([QuestionControl CheckQuestionWasAnswered:page])
{
pageNumber++;
NSLog(@"Proceed");
if(([loadedQuestionnaire count] - 1) != page)
{
[self loadScrollViewWithPage:page - 1]; …Run Code Online (Sandbox Code Playgroud) 我有一个视图,如果用户滚动它会更改.我需要一些东西来读取用户的滚动数据(方向,力等)UITableView.如果用户触摸屏幕并将手指移动到向上视图,则需要接收滚动数据以调用重绘方法.如何接收滚动数据?
我有一个UIScrollView内部我有一个UITableView滚动视图应该水平滚动.- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView当滚动视图结束其水平滚动时,我已经实现了一些任务.但我的问题是,即使UITableView垂直滚动也停止,这个代表也会触发.那么如何才能检测到scrollview该委托中的水平滚动?
请帮帮我,谢谢
ios ×9
uitableview ×6
iphone ×5
objective-c ×5
uiscrollview ×3
cocoa-touch ×2
direction ×1
pagination ×1
scroll ×1
swift ×1
swift3 ×1
uiview ×1
xcode ×1