8

私はもともとこの質問に対する答えを探していましたが、質問する前に解決策が思い浮かび、完全に機能しました。

基本的に、私の質問のように、iOS 7 では、視差で動くシャドウ レイヤーを使用できますか? 答えはイエスです。その方法は次のとおりです。

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.layer.masksToBounds = NO;
    self.view.layer.cornerRadius = 2; // if you like rounded corners
    self.view.layer.shadowOffset = CGSizeMake(1, 1);
    self.view.layer.shadowRadius = 2;
    self.view.layer.shadowOpacity = 0.5;
    UIInterpolatingMotionEffect *verticalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"layer.shadowOffset.height" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
    verticalMotionEffect.minimumRelativeValue = @(20);
    verticalMotionEffect.maximumRelativeValue = @(-20);

    UIInterpolatingMotionEffect *horizontalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"layer.shadowOffset.width" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
    horizontalMotionEffect.minimumRelativeValue = @(20);
    horizontalMotionEffect.maximumRelativeValue = @(-20);

    UIMotionEffectGroup *group = [UIMotionEffectGroup new];
    group.motionEffects = @[horizontalMotionEffect, verticalMotionEffect];

    [self.view addMotionEffect:group];
}

特に難しいことはありません。

4

0 に答える 0