2012-10-01 3 views
0

보기를 회전하고 크기를 조정하는 기능이있는 앱을 만들고 있습니다. 이 기능을 구현했지만 문제가 있습니다.UIView의 크기를 조정하는 방법 CGAffineTransformIdentity

내 문제

내가 양 방향으로 뷰를 회전 할 수 있습니다 크기를 조정 한 후, 네 모서리를 드래그하면보기 크기를 조정할 수 줘야 해.

일단 회전이 끝나면 모서리를 드래그하여 다시보기 크기를 조정하면보기의 크기가 예측할 수없는 값으로 이동하고 화면 전체가 이동합니다. 내가 많이 봤

결국 난 내가 구현하고자 정확히 어떤 기능을 구현하고 하나의 응용 프로그램을 본 다음과 같은 솔루션

The frame property is undefined when transform != CGAffineTransformIdentity, as per the docs on UIView 

을 얻었다. 뷰

의 크기를 조정하기위한

어떻게 UIView의 회전 후

내 코드를 UIView의 크기를 조정할 수 있습니다

접촉은

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 

    UITouch *touch = [[event allTouches] anyObject]; 

    NSLog(@"[touch view]:::%@",[touch view]); 

    touchStart = [[touches anyObject] locationInView:testVw]; 
    isResizingLR = (testVw.bounds.size.width - touchStart.x < kResizeThumbSize &&  testVw.bounds.size.height - touchStart.y < kResizeThumbSize); 
    isResizingUL = (touchStart.x <kResizeThumbSize && touchStart.y <kResizeThumbSize); 
    isResizingUR = (testVw.bounds.size.width-touchStart.x < kResizeThumbSize &&  touchStart.y<kResizeThumbSize); 
    isResizingLL = (touchStart.x <kResizeThumbSize && testVw.bounds.size.height -touchStart.y <kResizeThumbSize);  
} 

접촉이

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

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

NSLog(@"CVTM:%@",NSStringFromCGRect(testVw.frame)); 


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

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

} 
을 이전 개시
+0

나는 똑같은 문제가 있으며 이것에 대한 해결책이 있는지 궁금해하고 있습니다. 그렇다면 게시하십시오. 귀하의 회신에 감사드립니다. – Vad

답변

0

당신이 애니메이션의 UIView 사용하지 않기 때문에 당신은 절약 할 수 있습니다 현재보기의 변환 설정보기의 정체성에 변환 뷰의 크기를 조정하고 변환 저장 다시 적용 :

: 당신의 크기를 조정 정보

UIView *v; 
CGAffineTransform t = v.transform; 
v.transform = CGAffineTransformIdentity; 
CGFloat scale = 2.0f; 
v.frame = CGRectMake(v.frame.origin.x, v.frame.origin.y, v.frame.size.width*scale , v.frame.size.height*scale); 
v.transform = t; 

(EDIT)

A' = A 
C' = C' //touch input 
B' = A + (normalized(B-A) * dotProduct((C'-A), normalized(B-A))) 
D' = A + (normalized(D-A) * dotProduct((C'-A), normalized(D-A))) 

후미 : 당신은 4 개 벡터 (점) A, B, C, D (A+C)*.5 = (B+D)*.5 = rectangle_center 그런 다음 C의 위치를 ​​점 C를 이동 '도 B를 이동 것이고 D B로'와 D '로 사각형을 정의하는 경우 어 그 :

  • 는 변환을 만들/"의 경우"뷰의이 atanf(height/width) 거의 통해 변환 만들거나 채우기 위해
  • 세트 프레임 (.0f, .0f, length(A-D), length(A-C))
  • 세트 센터
  • (A+D)*.5f에 도착 회전에 정체성보기를 변환 normalized(D-A)normalized(B-A)

기본 벡터는 직사각형의 모든 점에 대해 수행 할 수 있습니다.

+0

. 이 방법을 시도했지만 작동하지 않습니다. – Gowtham

+0

코드에 실제로 다른 몇 가지 문제가 있습니다. 4 개의 이동 가능 포인트 만 가지고 시도한 다음 4 포인트에 따라 뷰를 설정하면 더 좋을 것이라고 생각합니다. 크기를 조정하고 이동하는 데 약간 더 많은 코드가 필요합니다. –

관련 문제