面临实现可拖动视图的一些困难。使用单点触控,但我不认为它是特定于语言的……问题的细节:我有一个处理TouchesBegan,TouchesMove和重新定位自身的视图(通过改变框架属性)。这真是太棒了!一旦我添加了禁用滚动和分页的ScrollView,在滚动视图上所做的任何触摸都不会到达必须移动的视图。将UserInteraction设置为NO可以修复移动问题,但滚动条中承载的所有控件都不会响应任何触摸。
你知道如何让ScrollView在没有滚动事件的情况下让它的superview接收到所有的触动吗?
发布于 2012-11-03 15:08:51
你必须将触控传递给subViews,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-03 17:02:55
您可以使用PanGesture操作拖动子视图...
-(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];
}
}https://stackoverflow.com/questions/13206850
复制相似问题