面对实施可拖动视图的一些困难。使用monotouch,但我不认为它是特定于语言的...... 问题详情: 我有一个View来处理TouchesBegan,TouchesMove并重新定位自己(通过更改Frame属性)。那工作完美! 一旦我添加ScrollView并禁用滚动和分页,滚动视图上的任何触摸都不会进入必须移动的视图。将UserInteraction设置为NO可修复移动问题,但滚动条内托管的控件均无响应任何触摸。
如果没有可用的滚动事件,有关如何使用ScrollView并允许其超级视图接收所有触摸的任何想法?
答案 0 :(得分: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
答案 1 :(得分: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];
}
}