0

在实现可拖动视图时面临一些困难。使用 monotouch,但我不认为它是特定于语言的......问题详细信息:我有一个处理 TouchesBegan、TouchesMove 和重新定位自身的视图(通过更改 Frame 属性)。那工作完美!一旦我添加了禁用滚动和分页的 ScrollView,在滚动视图上进行的任何触摸都不会到达必须移动的视图。将 UserInteraction 设置为 NO 可以解决移动问题,但滚动条内的任何控件都不会响应任何触摸。

关于如何拥有 ScrollView 并允许它的超级视图在没有可用滚动事件时接收所有触摸的任何想法?

4

2 回答 2

1

您必须将触摸传递给子视图,这个类别UIScrollView将完成这项工作:

@implementation UIScrollView (FixedApi)

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

    UITouch *touch = [[event allTouches] anyObject];

    NSLog(@"touch view = %@", [[touch view].class description]);
    if ([[[touch view].class description] isEqualToString:@"UITableView"]) {
        //You have touched a UITableView
    } else if ([[[touch view].class description] isEqualToString:@"UIView"]) {
        //You have touched a UIView
    } else {
         //Ignore the category and return the touch to the UIScrollView.
         [self.superview touchesBegan:touches withEvent:event]; // or 1 nextResponder, depends
         [super touchesBegan:touches withEvent:event];
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if ( !self.dragging ) [self.nextResponder.nextResponder touchesEnded:touches withEvent:event];
    [super touchesEnded:touches withEvent:event];
}

@end
于 2012-11-03T07:08:51.393 回答
0

您可以使用 PanGesture Action 拖动子视图...

-(void)panGRAction {

  if (panGR.state == UIGestureRecognizerStateBegan) {

        UITouch *touch = [[event allTouches] anyObject];

    NSLog(@"touch view = %@", [[touch view].class description]);
    if ([[[touch view].class description] isEqualToString:@"UITableView"]) {
        //You have touched a UITableView
    } else if ([[[touch view].class description] isEqualToString:@"UIView"]) {
        //You have touched a UIView
    } else {
         //Ignore the category and return the touch to the UIScrollView.
         [self.superview touchesBegan:touches withEvent:event]; // or 1 nextResponder, depends
         [super touchesBegan:touches withEvent:event];
    }

    } else if (panGR.state == UIGestureRecognizerStateEnded) {
if ( !self.dragging ) [self.nextResponder.nextResponder touchesEnded:touches withEvent:event];
    [super touchesEnded:touches withEvent:event];
}

}
于 2012-11-03T09:02:55.317 回答