[英]Transferring touches from uiview to uitableview
I setup my views like this, 我这样设定我的观点
+- MyView : UIView --------------------+
| A |
| +- MyTableView : UITableView -----+|
| | ||
| | B ||
| | ||
| +---------------------------------+|
+--------------------------------------+
I want to achieve following two points. 我想实现以下两点。
Initially, when user starts scrolling MyTableView I don't want to scroll MyTableView (B in the figure) instead I want to move MyView ( A in the figure) at certain point. 最初,当用户开始滚动MyTableView时,我不想滚动MyTableView(图中的B),而是要在特定点移动MyView(图中的A)。
After reaching a certain point I want start MyTableView scrolling. 达到某个点后,我要开始MyTableView滚动。 At this point table should get touch events and super view should NOT.
此时,表应该获得触摸事件,而超级视图则不应。 I want this to happen without lifting the touch.
我希望做到这一点而又不必费劲。
I'm able to achieve 1st part by following code each view's subclass 我可以通过遵循每个视图的子类的代码来实现第一部分
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
if ( _canReceiveTouches )
return YES;
return NO;
}
Where I enable/disable _canReceiveTouches , but I'm not able to achieve 2nd part without lifting the touch. 我在启用/禁用_canReceiveTouches的地方 ,但是如果不提高触摸度就无法实现第二部分。 I have to lift the touch to table view getting next touch event.
我必须将触摸移到表格视图以获取下一个触摸事件。
Can some one give me some pointers how to achieve this ? 有人可以给我一些指示如何实现这一目标吗? Thanks in advance.
提前致谢。
Implement touchesMoved:WithEvent:
实现
touchesMoved:WithEvent:
Inside the method, get the location (CGPoint) of the touch using: 在方法内部,使用以下方法获取触摸的位置(CGPoint):
CGPoint touchLocation = [touches anyObject] locationInView:self.view];
Then compare with the tableview's "top" y (aka origin.y). 然后,将其与表格视图的“顶部” y(也称为origin.y)进行比较。 You can get this using:
您可以使用以下方法获取此信息:
CGFloat tableViewOriginY = CGRectGetMinY(self.tableview.frame); CGFloat tableViewOriginY = CGRectGetMinY(self.tableview.frame);
Have a conditional statement checking if "touchLocation.y" is higher or equal than "tableViewOriginY", then you have reached the desired point and you can have your tableview scrolling. 有一条条件语句,检查“ touchLocation.y”是否大于或等于“ tableViewOriginY”,那么您已达到所需的位置,可以滚动tableview。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.