iOS的桌面背景运动效果

1
2
3
4
5
6
7
8
9
10
11
12
13
_backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(-50, -50, Screen_width+100, Screen_Height+100)];
_backgroundImage.image = [UIImage imageNamed:@"bg_1"];
[self.view addSubview:_backgroundImage];

UIInterpolatingMotionEffect * backEffX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];// type表示沿水平方向运行效果
backEffX.maximumRelativeValue = @(-50);
backEffX.minimumRelativeValue = @(50);
[self.backgroundImage addMotionEffect:backEffX];

UIInterpolatingMotionEffect * backEffY = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
backEffY.maximumRelativeValue = @(-50);
backEffY.minimumRelativeValue = @(50);
[self.backgroundImage addMotionEffect:backEffY];