UIView移动

发布于 2024-10-06 15:17:41 字数 421 浏览 0 评论 0原文

这是移动 UIView 的最佳方式。 我有一个自定义 UIView,其中包含一些自定义内容,例如阴影、标签等。

今天我正在使用,用于移动此 UIView。:

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    if (self.isEditing) {       
        CGPoint location = [touch locationInView:[rootView view]];      
        self.center = location; 
    }
}

这是移动 UIView 的最佳方式吗?我的经历有点滞后。

Which is the best way to move a UIView.
I have a custom UIView with some custom things in it, like shadows, labels etc.

Today I'm using, for move this UIView.:

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    if (self.isEditing) {       
        CGPoint location = [touch locationInView:[rootView view]];      
        self.center = location; 
    }
}

Is this the best way to move a UIView? I experience this a bit laggy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仲春光 2024-10-13 15:17:41

我通常使用touchesBegan位置和touchesMoves位置之间的偏移量来重新定位视图。

I usually reposition a view using the offset between the touchesBegan location and the touchesMoves location.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文