ios - 如何移动/重新排列触摸事件上的 View 位置?

标签 ios view

假设,在我的窗口上有 3 个 View ,主视图位于后台,另外 2 个 View 位于前面。

前面的每个 View 都包含一些内容,我希望在触摸时作为 View 的一部分移动。我所说的“移动”是指“相对于另一个 View 重新排列位置”。触摸后,我想“拾取包含所有内容的 View 并将其放置在当前由另一个 View 占据的位置”

enter image description here

您会从哪里开始做这样的事情?

最佳答案

类似这样的事情:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UIView *touchedView = [[touches anyObject] view];
    CGPoint location = [[touches anyObject] locationInView:touchedView];
    touchedView.center = location;
}

另请参阅 UIResponder.h 中的这些方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

关于ios - 如何移动/重新排列触摸事件上的 View 位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7850630/

相关文章:

android - Android 中的屏幕和 View 坐标

mysql - 字段列表中未知的列名 - MySQL

ios - 如何让自动布局在 Xcode 中工作

ios - 如何在弹出 subview 中有一个 UITableView?

asp.net-mvc - 在 ASP.NET MVC 上使用绝对路径访问 View

templates - symfony - 从 View 中调用一个 Action ?

sql - 如何从 Access 2010 中的 SQL 存储过程返回多个记录集

ios - Objective-C 中反斜杠 (\) 字符的使用

ios - 如何使用web3的个人分机签署个人消息?

ios - 如何在小数点键盘上显示完成按钮?