ある程度のサイズの UIView があります。そして、クリックしたボタンでそのビューのサイズを変更しています。ただし、UIView のサイズ変更は、 3:2 、 4:3 、 16:9 などの比率に依存します。また、比率に従って UIView のドラッグを行う必要があります。
kResizeThumbSize 30
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if ([((UIView *)(touch.view)) isEqual:canvas])
{
touchStart = [[touches anyObject] locationInView:canvas];
isResizingLR = (canvas.bounds.size.width - touchStart.x < kResizeThumbSize && canvas.bounds.size.height - touchStart.y < kResizeThumbSize);
isResizingUL = (touchStart.x <kResizeThumbSize && touchStart.y <kResizeThumbSize);
isResizingUR = (canvas.bounds.size.width-touchStart.x < kResizeThumbSize && touchStart.y<kResizeThumbSize);
isResizingLL = (touchStart.x <kResizeThumbSize && canvas.bounds.size.height -touchStart.y <kResizeThumbSize);
}
if(isResizingLR || isResizingUL|| isResizingLL || isResizingUR){
[canvas removeGestureRecognizer:panRecognizer];
}
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchPoint = [[touches anyObject] locationInView:canvas];
CGPoint previous=[[touches anyObject]previousLocationInView:canvas];
float deltaWidth = touchPoint.x-previous.x;
float deltaHeight = touchPoint.y-previous.y;
if (isResizingLR) {
canvas.frame = CGRectMake(canvas.frame.origin.x, canvas.frame.origin.y,touchPoint.x + deltaWidth, touchPoint.y + deltaWidth);
}
if (isResizingUL) {
canvas.frame = CGRectMake(canvas.frame.origin.x + deltaWidth, canvas.frame.origin.y + deltaHeight, canvas.frame.size.width - deltaWidth, canvas.frame.size.height - deltaHeight);
}
if (isResizingUR) {
canvas.frame = CGRectMake(canvas.frame.origin.x ,canvas.frame.origin.y + deltaHeight, canvas.frame.size.width + deltaWidth, canvas.frame.size.height - deltaHeight);
}
if (isResizingLL) {
canvas.frame = CGRectMake(canvas.frame.origin.x + deltaWidth ,canvas.frame.origin.y , canvas.frame.size.width - deltaWidth, canvas.frame.size.height + deltaHeight);
}
}