Motion Effects(iOS 7の「視差効果」の実装方法)

  • UIInterpolatingMotionEffect

  • UIMotionEffectGroup

// Create motion effects
UIInterpolatingMotionEffect*    xAxis;
UIInterpolatingMotionEffect*    yAxis;
xAxis = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
xAxis.minimumRelativeValue = [NSNumber numberWithFloat:-10.0 * DETAILCONTROLLER_MOTION_EFFECT_LAYER_LEVEL];
xAxis.maximumRelativeValue = [NSNumber numberWithFloat:10.0 * DETAILCONTROLLER_MOTION_EFFECT_LAYER_LEVEL];
    
yAxis = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
yAxis.minimumRelativeValue = [NSNumber numberWithFloat:-10.0 * DETAILCONTROLLER_MOTION_EFFECT_LAYER_LEVEL];
yAxis.maximumRelativeValue = [NSNumber numberWithFloat:10.0 * DETAILCONTROLLER_MOTION_EFFECT_LAYER_LEVEL];

// Create effect group
UIMotionEffectGroup*            group;
group = [[UIMotionEffectGroup alloc] init];
group.motionEffects = @[xAxis, yAxis];
    
// Add motion effect
[self.view addMotionEffect:group];

参考サイト

Designing Games with Sprite Kit, Session226