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

...

터치가 시작점과의 또한 중심점을 저장 시작

편집중인 이미지. (이미지의 수퍼 뷰와 관련된 모든 점).

그런 다음 눈금은 중심점에서 터치 거리에 비례합니다 (피타고라스 사용).

또한 중심점에서 원래의 터치까지의 각도를 알 수 있습니다 (삼각법 사용). 시작 각도와 현재 각도의 차이에 따라 이미지의 각도를 변경할 수 있습니다.

나는 터치를 움직이면 로직을 취하고 터치하면 기능이 시작됩니다. calculateRotation 함수와 calculateScale 함수를 사용하여 도움을줍니다.

현재로서는 코드를 작성할 수 없습니다.

+0

샘플 코드 –

+0

을 제공해 주실 수 있습니까? :) 초기 터치와 중심점 사이의 시작 거리를 저장하는 변수가 두 개 필요합니다. 하나는 초기 각도를 저장합니다. 그런 다음 각도를 계산하는 함수와 거리를 계산하는 함수가 필요합니다. 그런 다음 각도와 거리가 어떻게 변했는지에 따라 이미지를 확대/축소/회전 할 수 있습니다. – Fogmeister

+0

나는 그것에 대해 연구 할 것이다. 귀하의 응답을 보내 주셔서 감사합니다 –