[英]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
(具有相同的dataSource
和delegate
),但不要将其插入到视图层次结构中的任何位置; 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:
方法,将原始UITableView
的contentOffset
设置为重复的UITableView
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.