私はUIViewをユーザーのタッチに関連させて移動しようとしています。タッチとの関係でUIViewを移動
は、ここで私が現時点で持っているものです。
int oldX, oldY;
BOOL dragging;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(window.frame, touchLocation)) {
dragging = YES;
oldX = touchLocation.x;
oldY = touchLocation.y;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(window.frame, touchLocation) && dragging) {
CGRect frame;
frame.origin.x = (window.frame.origin.x + touchLocation.x - oldX);
frame.origin.y = (window.frame.origin.y + touchLocation.y - oldY);
window.frame = frame;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
dragging = NO;
}
ビューは、ある場所から別の場所にちらつき続け、私は何をする他に何かわかりません。
助けてください。
ウィンドウはドラッグしているオブジェクトですか? – EmptyStack
はい、Interface Builderで作成されたビューです。 –
これははるかに優れていますが、触ったときはいつでも奇妙に横にズームします。 –