简体   繁体   English

是否可以在按钮上启动scrollView平移手势

[英]Is it possible to start scrollView pan gesture on a button

I have a hierarchy like so 我有一个像这样的层次结构

- UIView 
   - UITableView
   - UIButton

By default swiping from a UIButton does not scroll the scroll view. 默认情况下,从UIButton滑动不会滚动滚动视图。 I want to change this so it does. 我想改变它,所以它确实如此。

I could do this by changing the UIButton to a UILabel and add a UITapGestureRecogniser to it to effectively make a custom button. 我可以通过将UIButton更改为UILabel并向其添加UITapGestureRecogniser来有效地创建自定义按钮。

Is there a way to do it keeping it as a UIButton? 有没有办法保持它作为UIButton?

在此输入图像描述

-(void)moveUpView
  {  
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:n inSection:0];
    [self.tableView scrollToRowAtIndexPath:indexPath      atScrollPosition:UITableViewScrollPositionTop
                                animated:YES];
        }


Hope this may work 希望这可行

Create a duplicate UITableView (with the same dataSource and delegate ), but don't insert it anywhere into the view hierarchy; 创建一个重复的UITableView (具有相同的dataSourcedelegate ),但不要将其插入到视图层次结构中的任何位置; just add its panGestureRecognizer to the UIButton . 只需将其panGestureRecognizer添加到UIButton Implement its delegate -scrollViewDidScroll: method to set the original UITableView 's contentOffset to that of the duplicate UITableView . 实现其委托-scrollViewDidScroll:方法,将原始UITableViewcontentOffset设置为重复的UITableView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM