2013-10-03 5 views
0

iPhone을 기울이는 방향으로 움직이고 싶은 NSObject 볼이 있습니다. 나는 전에 만지기 만하면 아무 것도하지 않았다. 만질 뿐이다. 나는 더 가파른 각도로 기울어 질 때 더 빨리 움직이기를 원합니다. 누구든지 나를 도울 수 있습니까?자이로 스코프를 사용하여 화면에서 NSObject를 이동하는 방법

나는 매우 가난 결과이기는하지만 사용하는 코드입니다

답변

0

: 당신이 그것을 검사 할 개선 할 수있는 내용을 확인할 수를 :

NSDate * lastDate=nil; 

-(void)didRotate:(CMRotationRate)rotationRate{ 
NSDate *newDate=[NSDate date]; 
CGPoint testCenter=[[[OverlayViewController sharedOverlay] testElement] center]; 
if (lastDate!=nil){ 
    NSLog(@"rotate x %f y %f, z %f", rotationRate.x, rotationRate.y, rotationRate.z); 
    NSTimeInterval interval=[newDate timeIntervalSinceDate:lastDate]; 
    CGRect topFrame=[[[OverlayViewController sharedOverlay] view] frame]; 
    float xAtan=atan(rotationRate.x); 
    float yAtan=atan(rotationRate.y); 

    float xRotation= topFrame.size.width*xAtan/interval; 
    float yRotation=topFrame.size.height*yAtan/interval; 
    NSLog(@"topHeight=%f yAtan=%f interval=%f yRotation=%f", topFrame.size.height, yAtan, interval, yRotation); 
    NSLog(@"interval %f rotation (%f,%f)", interval, xRotation, yRotation); 
    CGPoint newCenter=CGPointMake(testCenter.x+xRotation, testCenter.y+yRotation); 
    NSLog(@"old center (%f,%f) new center (%f,%f)", testCenter.x, testCenter.y, newCenter.x, newCenter.y); 
    [[[OverlayViewController sharedOverlay] testElement] setCenter:newCenter]; 
} 
lastDate=newDate; 
}