Objective c 如何使用不带精灵套件的CoreMotion向左和向右倾斜图像
如何使用不带精灵套件的CoreMotion向左和向右倾斜图像 大家好 我目前正在研究如何在没有精灵套件的情况下使用核心运动框架。在web上找不到任何。当iPhone向右倾斜时,有人能演示如何将图像向右移动吗。当它不使用雪碧套件而向左倾斜时Objective c 如何使用不带精灵套件的CoreMotion向左和向右倾斜图像,objective-c,Objective C,如何使用不带精灵套件的CoreMotion向左和向右倾斜图像 大家好 我目前正在研究如何在没有精灵套件的情况下使用核心运动框架。在web上找不到任何。当iPhone向右倾斜时,有人能演示如何将图像向右移动吗。当它不使用雪碧套件而向左倾斜时 this is what i have so far. does this look correct? CMMotionManager *motionManager = [[CMMotionManager alloc] init]; motionManag
this is what i have so far. does this look correct?
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
motionManager.deviceMotionUpdateInterval = 1.0/10.0;
if (!motionManager.isDeviceMotionAvailable) {
CGPointMake(Bird.center.x-1, Bird.center.y-upmovement);
您已关闭运动管理器的构造,但忘记开始获取更新 下面是一个基于您提供的内容的工作示例
CMMotionManager* motionManager = [[CMMotionManager alloc] init];
motionManager.deviceMotionUpdateInterval = 1/27; // 27 frames per second
// Start the motion manager with our queue
[motionManager startDeviceMotionUpdatesToQueue: [[NSOperationQueue alloc] init]
withHandler: ^(CMDeviceMotion *motion, NSError *error) {
CGFloat multiplier;
CGPoint newPosition;
if ( !motionManager || !Bird ) //make sure it is safe to invoke the motion manager, and the view.
return;
// The Movement Multiplier
multiplier = 200;
// The center point of which the view will reside
newPosition = Bird.superview.center;
// Calculate our new position
newPosition.x += motion.attitude.roll * multiplier;
newPosition.y += motion.attitude.pitch * multiplier;
// Move the view in the main thread so it can be rendered correctly.
dispatch_async( dispatch_get_main_queue(), ^{
Bird.center = newPosition;
});
}];
它应该在x轴和y轴上移动鸟瞰图