首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS可拖动子视图

iOS可拖动子视图
EN

Stack Overflow用户
提问于 2012-11-03 14:58:36
回答 2查看 338关注 0票数 0

面临实现可拖动视图的一些困难。使用单点触控,但我不认为它是特定于语言的……问题的细节:我有一个处理TouchesBegan,TouchesMove和重新定位自身的视图(通过改变框架属性)。这真是太棒了!一旦我添加了禁用滚动和分页的ScrollView,在滚动视图上所做的任何触摸都不会到达必须移动的视图。将UserInteraction设置为NO可以修复移动问题,但滚动条中承载的所有控件都不会响应任何触摸。

你知道如何让ScrollView在没有滚动事件的情况下让它的superview接收到所有的触动吗?

EN

Stack Overflow用户

发布于 2012-11-03 15:08:51

你必须将触控传递给subViews,UIScrollView的这个类别将完成这项工作:

代码语言:javascript
复制
@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
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13206850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档