我原本是在寻找这个问题的答案,但在我提出这个问题之前,解决方案就出现在了我身上,而且效果很好。
基本上,我的问题方式是,在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];
}
并不是特别困难。