嗨,标题预先总结了它,它正在使用加速度计,但它一直在屏幕外,我 15 岁,我在试图让它停在边缘时遇到了很多麻烦。这是我的视图 controller.m 文件代码。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize person, delta;
- (void)viewDidLoad
{
UIAccelerometer *accel =[UIAccelerometer sharedAccelerometer];
accel.delegate = self;
accel.updateInterval = 1.0f / 60.0f;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)accelerometer:(UIAccelerometer *)accelerometer
didAccelerate:(UIAcceleration *)acceleration{
NSLog(@"x : %g", acceleration.x);
NSLog(@"y : %g", acceleration.y);
NSLog(@"z : %g", acceleration.z);
delta.x = acceleration.y *50;
// delta.x = acceleration.x *8;
person.center = CGPointMake(person.center.x + delta.x,person.center.y + delta.y );
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end