我正在尝试移动位于另一个 UIView 之上的 UIView(我们称之为 viewA)(我们称之为 viewB)。viewB 有 iPad 屏幕的大小,而 view A 要小得多。
我设法移动东西,但整个屏幕移动(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)) { 拖动=是; 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 类中实现了这些方法。“我”应该关注这个viewA吧?那么为什么当我的手指在屏幕上移动时整个页面都会移动呢?