我正在尝试 move 一个 UIView(我们称之为 viewA),它位于另一个 UIView(我们称之为 viewB)之上。 viewB 具有 iPad 屏幕的大小,而 View A 则小得多。
我设法 move 东西,但整个屏幕都 move (viewA + viewB),而不仅仅是 viewA。
这是我的 viewA 类代码:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint touchLocation = [touch locationInView:self->view]; if (CGRectContainsPoint(self.window.frame, touchLocation)) { dragging = YES; oldY = touchLocation.y; } }- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint touchLocation = [touch locationInView:self->view]; if (dragging) { CGRect frame = self.window.frame; frame.origin.y = self.window.frame.origin.y + touchLocation.y - oldY; self.window.frame = frame; } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { dragging = NO; }
我不明白的是,我在 viewA 类中实现了这些方法。 “ self ”应该关注这个观点吧?那么为什么当我的手指在屏幕上 move 时整个页面都会 move 呢?
最佳答案
您正在 move 整个窗口,其中包含所有 View ,您应该只 move 您想要的 View ,在您的情况下为 viewA。
关于ios - 用手指 move UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10411182/