2

我已经向 UIScrollView 添加了一个子视图。当我放大滚动视图时,我想平移子视图。

touchesBegan:我得到触摸的初始位置,然后touchesMoved:我能够确定移动子视图的程度。zoomscale它在1.0时完美运行。但是,当它被缩放时,指针会从它打算移动的子视图中“跳出”(此处的插图 - 指针位置显示为选取框工具)。

视图的中心应该在指针位置,而不是在它的当前位置!px 和 py 变量确保单击子视图上的任何位置,同时拖动它时指针的位置始终保持不变。插图

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    location.x = location.x * self.zoomScale;
    location.y = location.y * self.zoomScale;
    px = location.x;
    py = location.y;
    if ([touch view] == rotateView) {
        self.scrollEnabled = NO;
        return;
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    location.x = location.x * self.zoomScale;
    location.y = location.y * self.zoomScale;
    if ([touch view] == rotateView) {
        rotateView.center = CGPointMake(rotateView.center.x + (location.x - px), rotateView.center.y + (location.y - py));
        px = location.x;
        py = location.y;
        return;
    }

    }

4

1 回答 1

1

代替您采用的方法,使子视图成为另一个 UIScrollView 并让它处理平移。

(您可能希望scrollEnabled = NO在您的子视图上设置,直到发生缩放。)

于 2013-11-04T10:47:20.600 回答