scrollview手势冲突问题

解决iOS 加在UIScrollView上的UITableView滑动手势冲突问题办法
作者:用户
本文讲的是解决iOS 加在UIScrollView上的UITableView滑动手势冲突问题办法,
在UITableView里面实现cell的左滑删除功能是挺简单的,一般大家都会做。但是,如果把UITableView加在UIScrollView上的时候,就会产生一系列的问题。
首先阐明是因为UITableView列表太宽,超出了
在UITableView里面实现cell的左滑删除功能是挺简单的,一般大家都会做。但是,如果把UITableView加在UIScrollView上的时候,就会产生一系列的问题。
首先阐明是因为UITableView太宽,超出了屏幕的宽度,所以只好加在UIScrollView上,控制UIScrollView的contentSize实现列表的左右滑动。
一般我们的用户体验都是希望表格是紧贴屏幕边框,不让用户看到屏幕多余出来的部分,这时候就要把UIScrollView的属性bounces给关闭,设置为NO,也就是所谓的弹簧效果。
下面我们来说说把UITableView加在UIScrollView上的时候,产生的问题:
有些项目要求给UITableView做左滑删除功能,但是这个UITableView列表是加在UIScrollView上的,这时候如果你向左滑动,你会发现没法看到左滑出来的删除按钮,但是也有时候会出来,我想可能是这时候的手势滑动响应在了UITableView身上,这就是滑动手势冲突的问题。经过一番查阅资料,终于找到了解决办法,办法就是重写UIScrollView类,继承UIScrollView。
MyScrollview.h文件
#import &UIKit/UIKit.h&
@interface MyScrollview : UIScrollView&UIGestureRecognizerDelegate&
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureR
MyScrollview.m文件
#import "MyScrollview.h"
@implementation MyScrollview
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (gestureRecognizer.state != 0) {
return YES;
return NO;
接下来就可以在主界面ViewController里导入#import “MyScrollview.h”,使用MyScrollview代替UIScrollView。
附上我写的一个小demo代码:
#import "ViewController.h"
#import "sideslipTableViewCell.h"
#import "MyScrollview.h"
@interface ViewController ()&UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate&{
UITableView *sideslipTableV
NSMutableArray *dataA
MyScrollview *mainScrollV
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initUI];
dataArray = [NSMutableArray arrayWithArray: @[@"1111",@"2222",@"3333",@"4444",@"5555",@"6666",@"7777",@"8888",@"9999"]];
#pragma mark - 初始化UI
- (void)initUI{
self.view.backgroundColor = RGB(242, 242, 247);
self.automaticallyAdjustsScrollViewInsets = NO;
mainScrollView = [[MyScrollview alloc] initWithFrame:CGRectMake(0, 44 + 10, kScreenWidth, kScreenHeight - 44 - 10)];
mainScrollView.bounces = NO;
mainScrollView.delegate =
[mainScrollView setDelaysContentTouches:NO];
[mainScrollView setCanCancelContentTouches:NO];
[self.view addSubview:mainScrollView];
sideslipTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 60, 440, kScreenHeight - 60) style:UITableViewStylePlain];
sideslipTableView.backgroundColor = [UIColor clearColor];
sideslipTableView.delegate =
sideslipTableView.dataSource =
sideslipTableView.separatorStyle = UITableViewCellSeparatorStyleN
[mainScrollView addSubview:sideslipTableView];
mainScrollView.contentSize = CGSizeMake(440, 0);
#pragma mark - 行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return dataArray.
#pragma mark - 行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 46;
#pragma mark - cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *indefier = @"cell";
sideslipTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indefier];
if (!cell) {
cell = [[sideslipTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indefier];
cell.selectionStyle = UITableViewCellSelectionStyleN
cell.lable.text = dataArray[indexPath.row];
//先要设Cell可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
return YES;
//定义编辑样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
return UITableViewCellEditingStyleD
//进入编辑模式,按下出现的编辑按钮后,进行删除操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
if (editingStyle == UITableViewCellEditingStyleDelete) {
[dataArray removeObjectAtIndex:indexPath.row];
// Delete the row from the data source.
[sideslipTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
//修改编辑按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
return @"删除";
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
这里实现的是左滑删除的功能,如果你需要实现左滑出现多个按钮,如:删除和关闭,将上面的方法- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath 注释掉,然后实现下面的方法:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *deleteRoWAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {//title可自已定义
NSLog(@"点击删除");
deleteRoWAction.backgroundColor = RGB(210, 207, 209);
//此处是iOS8.0以后苹果最新推出的api,UITableViewRowAction,Style是划出的标签颜色等状态的定义,这里也可自行定义
UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"关闭" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击关闭");
editRowAction.backgroundColor = [UIColor redColor];//可以定义RowAction的颜色
return @[editRowAction,deleteRoWAction];//最后返回这俩个RowAction 的数组
注意:下面这两个属性必须加上:
[mainScrollView setDelaysContentTouches:NO];
[mainScrollView setCanCancelContentTouches:NO];
// 当前屏幕宽度
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
// 当前屏幕高度
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索uiscrollview手势冲突、uiscrollview滑动手势、uiscrollview滑动冲突、uitableview手势冲突、uitableview 滑动手势,以便于您获取更多的相关知识。
稳定可靠、可弹性伸缩的在线数据库服务,全球最受欢迎的开源数据库之一
6款热门基础云产品6个月免费体验;2款产品1年体验;1款产品2年体验
弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率
开发者常用软件,超百款实用软件一站式提供
云栖社区()为您免费提供相关信息,包括
uiscrollview手势冲突、uiscrollview滑动手势、uiscrollview滑动冲突、uitableview手势冲突、uitableview 滑动手势的信息
,所有相关内容均不代表云栖社区的意见!&>&UIScrolloerView手势冲突
UIScrolloerView手势冲突
上传大小:60KB
解决UISuperScrollerView上add SubScrollerVie时候 当滑动SubScrollerVie时候禁止相应UISuperScrollerView滑动事件
综合评分:0(0位用户评分)
所需积分/C币:
下载个数:0
{%username%}回复{%com_username%}{%time%}\
/*点击出现回复框*/
$(".respond_btn").on("click", function (e) {
$(this).parents(".rightLi").children(".respond_box").show();
e.stopPropagation();
$(".cancel_res").on("click", function (e) {
$(this).parents(".res_b").siblings(".res_area").val("");
$(this).parents(".respond_box").hide();
e.stopPropagation();
/*删除评论*/
$(".del_comment_c").on("click", function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_invalid/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parents(".conLi").remove();
alert(data.msg);
$(".res_btn").click(function (e) {
var q = $("#form1").serializeArray();
console.log(q);
var res_area_r = $.trim($(".res_area_r").val());
if (res_area_r == '') {
$(".res_text").css({color: "red"});
$.post("/index.php/comment/do_comment_reply/", q,
function (data) {
if (data.succ == 1) {
var $target,
evt = e || window.
$target = $(evt.target || evt.srcElement);
var $dd = $target.parents('dd');
var $wrapReply = $dd.find('.respond_box');
console.log($wrapReply);
var mess = $(".res_area_r").val();
var str = str.replace(/{%header%}/g, data.header)
.replace(/{%href%}/g, 'http://' + window.location.host + '/user/' + data.username)
.replace(/{%username%}/g, data.username)
.replace(/{%com_username%}/g, _username)
.replace(/{%time%}/g, data.time)
.replace(/{%id%}/g, data.id)
.replace(/{%mess%}/g, mess);
$dd.after(str);
$(".respond_box").hide();
$(".res_area_r").val("");
$(".res_area").val("");
$wrapReply.hide();
alert(data.msg);
}, "json");
/*删除回复*/
$(".rightLi").on("click",'.del_comment_r', function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_comment_del/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parent().parent().parent().parent().parent().remove();
$(e.target).parents('.res_list').remove()
alert(data.msg);
//填充回复
function KeyP(v) {
$(".res_area_r").val($.trim($(".res_area").val()));
评论共有0条
审核通过送C币
Ray Wenderlich 书籍
创建者:fengqingli
iOS开发学习电子书
iOS电子图书大全
创建者:qq_
上传者其他资源上传者专辑
ios Coder 归档
iOS crash log
二维码制作
UIPageViewController与系统右滑返回手势冲突问题
MMDrawerController手势冲突
移动开发热门标签
VIP会员动态
下载频道用户反馈专区
下载频道积分规则调整V1710.18
开通VIP,海量IT资源任性下载
spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip
CSDN&VIP年卡&4000万程序员的必选
为了良好体验,不建议使用迅雷下载
UIScrolloerView手势冲突
会员到期时间:
剩余下载个数:
剩余C币:593
剩余积分:0
为了良好体验,不建议使用迅雷下载
积分不足!
资源所需积分/C币
当前拥有积分
您可以选择
程序员的必选
绿色安全资源
资源所需积分/C币
当前拥有积分
当前拥有C币
(仅够下载10个资源)
全站600个资源免积分下载
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
全站600个资源免积分下载
资源所需积分/C币
当前拥有积分
当前拥有C币
您的积分不足,将扣除 10 C币
全站1200个资源免积分下载
为了良好体验,不建议使用迅雷下载
你当前的下载分为234。
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
UIScrolloerView手势冲突iOS 手势与点击事件冲突的解决方案 - CSDN博客
iOS 手势与点击事件冲突的解决方案
问题描述:
当页面内容加载失败时展现可以点击重新加载的错误页(点击重新加载使用的是单击手势),当页面重新加载成功出现tableViewCell后,移除错误页,但点击页面仍然响应单击手势,而不是响应cell的点击效果。
解决方案:
1、遵守手势的协议
UIGestureRecognizerDelegate
2、实现其代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"])
return NO;
if ([touch.view isKindOfClass:[UITableView class]]
return NO;
return YES;
本文已收录于以下专栏:
相关文章推荐
前几天在做项目的时候,遇到这个一个问题,在一个视图也就是UIView上添加一个手势,然后又在这个View上添加一个UIButton,然后给按钮添加事件,运行项目的时候我发现,不管是点击按钮还是视图上的...
今天发现如果直接在leftBarItem添加一个自定义button的时候,这个button的有效点击范围将会很大,接近navigationBar的titleview。
有时候我们不想要这种特性。可以这...
不知道各位在做开发的时候,是否有在同一个页面里既有单击的手势,又有tableView的存在的情况,如果有的话,你可能会发现,你的tableView点击出问题了,打印一下,你会发现,你单击tableVi...
原文链接:http://blog.csdn.net/likendsl/article/details/0;ios的手势操作之UIGestureRecognizer浅析
手势识别是具有互...
1.添加手势到collectionView并设置代理
UITapGestureRecognizer *innoCollTap = [[UITapGestureRecognizer alloc] in...
给UIPanGestureRecognizer添加代理(UIGestureRecognizerDelegate),UIGestureRecognizerDelegate中有一个方法:
做目前这个项目的时候,在自定义tableView里重写了touchesBegan、touchesMoved、touchesEnded几种方法,后来发现这样点击cell的时候,没有任何响应,搜索了很多都...
ViewPager里面经常会放置很多东西,本文提供一个解决思路。
子空间不使用OnClickListener,而使用OnTouchListener:
class OnClick implements ...
iOS中手势与UI控件之间的事件冲突解决方案
iOS中,多手势之间的冲突和解决方案
他的最新文章
讲师:宋宝华
讲师:何宇健
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)解决手势冲突 - 简书
解决手势冲突
tableviewcell可以触发点击,同时tableview的父视图有点击识别,这样点击的时候就会产生冲突。解决方法在GestureRecgnizer代理方法里面区分手势。
#pragma mark tapGestureRecgnizerdelegate 解决手势冲突
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UITableView class]]){
return NO;
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
return NO;
return YES;
两个控件之间的手势冲突
我在一个横向滚动的scrollview里面加了一个竖向滚动的tableview,这时如果实现了scrollview的代理方法却没有区分scrollview和tableview,这时候tableview的滚动会发生混乱。解决方法是在didScroll代理方法里区分这两个。
#pragma mark - scrollView delegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if ([scrollView isKindOfClass:[UITableView class]]) {
// NSLog(@"------是列表---");
// NSLog(@"------是滚动试图----");
UIScrollView和子视图TableView的cell右滑删除冲突
横向滚动的scrollview里面有一个子视图tableview,tableview的cell右右滑冲突,除非手指激活tracking停留一会儿,否则无法激活右滑删除。解决办法类似上面的,scrollview的左右滑依旧是由UIPanGesturerRecognizer控制的,但是该手势的代理无法更改
// Use these accessors to configure the scroll view's built-in gesture recognizers.
// Do not change the gestures' delegates or override the getters for these properties.
@property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer NS_AVAILABLE_IOS(5_0);
写一个UIScrollView的子类重写下面的方法即可:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
//NSLog(@"手势触发的类=%@",NSStringFromClass([touch.view class]));
// 若为UITableViewCellContentView(即点击了tableViewCell),则不截获Touch事件
if ([NSStringFromClass([touch.view class])isEqualToString:@"UITableViewCellContentView"]) {
return NO;
return YES;
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
// 若为UITableViewCellContentView(即点击了tableViewCell),则不截获Touch事件
if ([NSStringFromClass([gestureRecognizer.view class])isEqualToString:@"UITableViewCellContentView"]) {
return NO;
return YES;
Enjoy the life

我要回帖

更多关于 scrollview手势冲突 的文章

 

随机推荐