来自UIScrollview的视图的前瞻性和手势 [英] Forward Touches and Gestures to Views from UIScrollview

查看:98
本文介绍了来自UIScrollview的视图的前瞻性和手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在转发手势和触摸方面遇到了一些麻烦。我玩了很多,但是我不能按照我想要的方式工作。

I have some trouble with forwarding gestures and touches. I played around with it quite a bit, but i cant get it working the way I want.

基本上我想用2个手指和前进来控制双屏幕上的滚动视图覆盖滚动视图背后的ipad视图的其他所有内容。

Basically I want to control a scrollview on a dualscreen with 2 fingers and forward everything else to the ipad-views behind a overlaying scrollview.

为了能够控制双屏幕上的滚动视图我已经子类 UIScrollView 并将其添加为具有清晰背景的覆盖视图到ipad屏幕。

To be able to control the scrollview on the dualscreen I subclassed UIScrollView and added it as a overlaying view with a clear background to the ipad-screen.

然后我与代表联系起来将其拖动和内容转发给双屏幕上的滚动视图。这非常有效。

Then I hooked it up with a delegate to forward its dragging and stuff to the scrollview on the dualscreen. this works perfectly.

正如我写的那样,我希望scrollview只响应2个手指滚动,所以我把它设置为

As I wrote I want the scrollview to respond just to 2 finger-scroll, so i set it to

ScrollView.panGestureRecognizer.minimumNumberOfTouches = 2;

但是滚动视图会消除所有触摸,我不能正确地转发其他所有内容但只需要2个手指触摸对于背后的观点。
我认为重写

But the scrollview eats up all touches and I dont get it right to forward everything else but 2 finger touches to the views behind. I think overriding the

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

必须要做的伎俩,但我无法正确检测屏幕上的手指数量对。

must do the trick, but I don't get it right to detect the number of fingers on the screen right.

推荐答案

我想分享/解释问题的解决方案。这就是说我也想指出,孵化输入使我朝着正确的方向发展。非常感谢你的配偶!

I'd like to share/explain the solution to the problem. That said I also want to point out that hatfinch input led me in the right direction. thank you very very much mate!

当试图将视图/滚动视图作为覆盖的玩家时,问题是该玩家不知道它的下一个响应者。将视图/滚动视图作为底层视图将解决此问题。
您可能需要微调该底层滚动视图中任何滚动视图的触摸行为以获得正确的行为(如设置最大触摸次数)

The problem when attempting to put a view/scrollview as an overlaying toplayer is that the toplayer doesnt know about its "next responder". putting the view/scrollview as a underlaying view will solve this problem. you may need to fine tune the touch behaviour of any scrollview within that underlaying scrollview to get the behaviour right (like setting maximum number of touches)

解决方案是子类化UIScrollview,覆盖此方法
覆盖touchesBegan :和其他触摸方法如下(请参阅user1085093答案),并将其作为底层视图添加到ipad屏幕。

The solution is to subclass a UIScrollview, override this methods override the touchesBegan: and other touch methods as follows (see user1085093 answer), and add it as underlaying view to the ipad-screen.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

// If not dragging, send event to next responder
if (!self.dragging){
    [self.nextResponder touchesBegan: touches withEvent:event];
}
else{
    [super touchesBegan: touches withEvent: event];
}}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

// If not dragging, send event to next responder
if (!self.dragging){
    [self.nextResponder touchesMoved: touches withEvent:event];
}
else{
    [super touchesMoved: touches withEvent: event];
}}


-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

// If not dragging, send event to next responder
if (!self.dragging){
    [self.nextResponder touchesEnded: touches withEvent:event];
}
else{
    [super touchesEnded: touches withEvent: event];
}}

我像这样设置了scrollview:

i did the setup of the scrollview like this:

 TopLayerScrollView *newScrollView = [[TopLayerScrollView alloc] init];
[newScrollView setBackgroundColor:[UIColor clearColor]];
[newScrollView setFrame:self.tabBarController.view.frame];
[newScrollView setContentSize:dualScreenViewController.scrollContent.contentSize];
newScrollView.showsHorizontalScrollIndicator = NO;
newScrollView.showsVerticalScrollIndicator = NO;
newScrollView.delegate = self;
newScrollView.bounces = NO;
[newScrollView scrollsToTop];
newScrollView.panGestureRecognizer.minimumNumberOfTouches = 2;

self.topLayerScrollView = newScrollView;
[newScrollView release];

[self.tabBarController.view removeFromSuperview];
[topLayerScrollView addSubview:self.tabBarController.view];
[window addSubview:topLayerScrollView];
[topLayerScrollView bringSubviewToFront:self.tabBarController.view];

底层滚动视图的委托方法:

The delegate method of the underlaying scrollview:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.dragging || scrollView.tracking)
{
    [dualScreenViewControlleremphasized text.scrollContent setContentOffset:CGPointMake(scrollView.contentOffset.x, scrollView.contentOffset.y) animated:NO];
    self.tabBarController.view.frame = CGRectMake(scrollView.contentOffset.x, scrollView.contentOffset.y, self.tabBarController.view.frame.size.width, self.tabBarController.view.frame.size.height);
}}

此解决方案效果很好。
另一种解决方案是将滚动视图作为我最初想要的覆盖视图。如上所述,问题是让toplayer视图了解有关视图(nextResponder)的信息。要实现此目的,您必须对UIScrollview进行子类化并创建一个UIResponder属性,您必须在接口构建器文件中或在运行时期间进行连接。这样,覆盖的滚动视图将知道谁是下一个响应者。
请查看morningstar的回答

This solution works great. The other solution would be to have a scrollview as an overlaying view as I first intended. As said the problem is to let the toplayer view know about the views(nextResponder) benath it. To achive this you must sublass UIScrollview and create a UIResponder-property you must hookup either in your interface-builder file or during runtime. this way the overlaying scrollview will know who is the next responder. please see morningstar's answer

这篇关于来自UIScrollview的视图的前瞻性和手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆