2011-08-26 1 views

答えて

0
@interface FirstViewController : UIViewController <UIAccelerometerDelegate> { 
    IBOutlet UIImageView *imageView; 
    CGPoint delta; 
    CGPoint translation; 
    float ballRadius; 
} 

//implementation 

- (void)viewDidLoad 
{  
    [super viewDidLoad]; 

    // for the line in the middle of the camera 
    UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer]; 
    accel.delegate = self; 
    accel.updateInterval = 1.0f/60.0f;   
} 

- (void)accelerometer:(UIAccelerometer *)acel 
     didAccelerate:(UIAcceleration *)acceleration { 

    // Get the current device angle 
    float xx = -[acceleration x]; 
    float yy = [acceleration y]; 
    float angle = atan2(yy, xx); 

    // Add 1.5 to the angle to keep the image constantly horizontal to the viewer. 
    [imageView setTransform:CGAffineTransformMakeRotation(angle+1.5)]; 

} 
+0

ありがとう!コードスニペットは質問に答えることができますが、説明などのようにいくつかの追加情報を追加することはまだ素晴らしいです。 – j0k

関連する問題