我已经向 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;
}
}