ios - 放大后平移 UIScrollView 的 subview

标签 ios objective-c uiscrollview

我已经向 UIScrollView 添加了一个 subview 。当我放大 ScrollView 时,我想在 subview 周围平移。

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

View 的中心应该位于指针位置,而不是当前位置! px 和 py 变量确保 subview 上的任何地方被点击,而拖动它时指针的位置始终保持不变。 illustration

- (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;
    }

}

最佳答案

代替您采用的方法,将 subview 设为另一个 UIScrollView 并让它处理平移。

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

关于ios - 放大后平移 UIScrollView 的 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19760846/

相关文章:

ios - XCode 项目 : how to remove/add files from terminal (script, 命令等)

objective-c - 需要将 Tapku 日历设置为仅可选择特定日期吗?

ios - UIWebView 水平弹跳不起作用

iphone - UIScrollView objectAtIndex

iphone - 在启用分页和多个图像的情况下缩放 UIScrollView

php - 如何保存推送通知的设备 ID - iOS

ios - 这段代码使用 switch-case 和 if else if else 哪个更好?

ios - UISearchbar占位符错位

objective-c - 使用 NSPredicate 分析字符串

iphone - 当 iPhone 上的应用程序崩溃时如何发送电子邮件?