【发布时间】:2012-12-16 02:18:11
【问题描述】:
我有一个大小不一的 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);
}
}
【问题讨论】: