0

嗨我有一个需求,我需要调整其大小并通过拖动图像视图的右角来旋转图像视图。如何通过拖动图像视图的右下角来调整图像视图的大小并旋转图像视图

我可以通过拖动角落成功调整图像视图的大小,但是当我试图用单指针实现图像视图的大小调整旋转功能时失败。

任何人都可以指导我达到我的要求。

我已经添加了下面的代码来调整图像视图的边角。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
UITouch *touch = [[event allTouches] anyObject]; 
touchStart = [[touches anyObject] locationInView:self]; 
isResizingLR = (self.bounds.size.width - touchStart.x < kResizeThumbSize && self.bounds.size.height - touchStart.y < kResizeThumbSize); 
isResizingUL = (touchStart.x <kResizeThumbSize && touchStart.y <kResizeThumbSize); 
isResizingUR = (self.bounds.size.width-touchStart.x < kResizeThumbSize && touchStart.y<kResizeThumbSize); 
isResizingLL = (touchStart.x <kResizeThumbSize && self.bounds.size.height -touchStart.y <kResizeThumbSize); 

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 
CGPoint touchPoint = [[touches anyObject] locationInView:self]; 
CGPoint previous=[[touches anyObject]previousLocationInView:self]; 

float deltaWidth = touchPoint.x-previous.x; 
float deltaHeight = touchPoint.y-previous.y; 

if (isResizingLR) { 
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,touchPoint.x + deltaWidth, touchPoint.y + deltaWidth); 
} 
if (isResizingUL) { 
    self.frame = CGRectMake(self.frame.origin.x + deltaWidth, self.frame.origin.y + deltaHeight, self.frame.size.width - deltaWidth, self.frame.size.height - deltaHeight); 
} 
if (isResizingUR) { 
    self.frame = CGRectMake(self.frame.origin.x ,self.frame.origin.y + deltaHeight, self.frame.size.width + deltaWidth, self.frame.size.height - deltaHeight);  
} 
if (isResizingLL) { 
    self.frame = CGRectMake(self.frame.origin.x + deltaWidth ,self.frame.origin.y , self.frame.size.width - deltaWidth, self.frame.size.height + deltaHeight); 
} 

if (!isResizingUL && !isResizingLR && !isResizingUR && !isResizingLL) { 
    self.center = CGPointMake(self.center.x + touchPoint.x - touchStart.x,self.center.y + touchPoint.y - touchStart.y); 
} 

}

回答

1

喜按这个代码示例Here

试试这个...

我希望它会帮助你...

尝试一下本作旋转调整的UIImageView ...

self.imgViewForBend.layer.anchorPoint = CGPointMake(0.0,1.0); 
self.imgViewForBend.layer.position = CGPointMake(200,300.0); 
CGAffineTransform cgaRotateHr = CGAffineTransformMakeRotation(-(3.141/4)); 
[self.imgViewForBend setTransform:cgaRotateHr]; 
+0

感谢Spynet,但这段代码可以帮助我调整大小,相反我需要一些示例来旋转imageView,就像调整大小一样... –

+0

@vivek你想让代码旋转...? – Spynet

+0

@vivek我更新了代码检查它适合你... – Spynet

0

无需任何代码,我会想到这样的事情...

当触摸开始存储起点和也的中心点您正在编辑的图像。 (相对于图像的超视图的所有点)。

然后缩放比例是相对于中心点的触摸距离(使用pythagorus)。

此外,您将知道从中心点到原始触摸线的使用三角函数的角度。您可以根据起始角度和当前角度之间的差异更改图像的角度。

我也将逻辑从触摸移动和触摸开始功能。使用calculateRotation函数和calculateScale函数来提供帮助。

尽管现在不能编码。

+0

你能否提供样品代码 –

+0

当然,这是你的一部分? :)您需要一些变量,一个用于存储初始触摸和中心点之间的起始距离。一个存储初始角度。然后你需要一个函数来计算角度,一个计算距离。然后根据角度和距离的变化,您可以相应地缩放/旋转图像。 – Fogmeister

+0

我会努力的。感谢您的回复 –