ビューがあり、その中にUIImage
. 画像は静的ではなく、指をドラッグすると (ドラッグ イベントを使用して) 移動できます。問題は、画像がUIView
フレームの外に移動する場合があることです。親フレームの境界内に保持する適切な方法は何ですか?
--UIViewA
--------UIViewB
--------------UIImage
--------------UIボタン
UIViewB 内に UIImage を保持したい
- (IBAction)myButtonSingleTap:(UIButton *)sender {
imDragging = YES;
[_myButton addTarget:self action:@selector(dragBegan:withEvent:) forControlEvents: UIControlEventTouchDown];
}
- (IBAction)myButtonDragInside:(UIButton *)sender
{
[_myButton addTarget:self action:@selector(draging:withEvent:) forControlEvents: UIControlEventTouchDragInside];
}
- (void)dragBegan:(UIControl *)c withEvent:ev {
UITouch *touch = [[ev allTouches] anyObject];
startingTouchPoint = [touch locationInView:self.view];
}
- (void)draging:(UIControl *)c withEvent:ev {
UITouch *touch = [[ev allTouches] anyObject];
currentTouchPoint = [touch locationInView:self.view];
_movingPic.frame = CGRectMake(currentTouchPoint.x, currentTouchPoint.y, 28, 23);
}