2011-03-18 2 views
1

안녕하세요 모두 단일 손가락 터치로 UIView를 회전시키고 싶습니다. iPhone의 화면에서 손가락이 움직일 때까지 계속 회전하고 손가락을 움직이지 않거나 화면에서 제거하면 회전이 멈 춥니 다.UIView Rotation

미리 감사드립니다.

답변

8

는 유사한 코드를 시도

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

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.2]; 
    CGAffineTransform rr=CGAffineTransformMakeRotation(5); 
    yourView.transform=CGAffineTransformConcat(yourView.transform, rr); 
    [UIView commitAnimations]; 
} 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    [self touchesBegan:touches withEvent:event]; 
} 
+0

고맙습니다 도움이 될 수 있습니다 .... – JKMania

+0

및 감사는 투표에 너무 .... – JKMania

6

Pradeepa의 코드가 좋은, 그러나, 애니메이션 시스템이 (아직없는 경우) 사용되지지고 있습니다.

CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
double startRotationValue = [[[yourView.layer presentationLayer] valueForKeyPath:@"transform.rotation.z"] doubleValue]; 
rotation.fromValue = [NSNumber numberWithDouble:startRotationValue]; 
rotation.toValue = [NSNumber numberWithDouble:startRotationValue+5]; 
rotation.duration = 0.2; 
[yourView.layer addAnimation:rotation forKey:@"rotating"]; 

내가 그들을 비교할 수 있도록 Pradeepa의 번호를했다,하지만 난 애플이 대신 기존 시스템의 또는 블록 기반의 애니메이션을 사용을 선호 생각이 대신 같은 것을보십시오.

+0

고맙습니다 남자는 ..... 당신은 정말 내 시간을 절약 .. ... 고맙습니다. – JKMania

+0

감사합니다. 시간을 맛보십시오. – user268743