假设,在我的窗口上有 3 个 View ,主视图位于后台,另外 2 个 View 位于前面。
前面的每个 View 都包含一些内容,我希望在触摸时作为 View 的一部分移动。我所说的“移动”是指“相对于另一个 View 重新排列位置”。触摸后,我想“拾取包含所有内容的 View 并将其放置在当前由另一个 View 占据的位置”
您会从哪里开始做这样的事情?
最佳答案
类似这样的事情:
- (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/