As you may know that the iOS 7 home screen can do a visual things like, when the user moving the device, the background is moving as well. How can I do the similar thing in my application? Let say I got two images view. One is on top of another. How to implement the similar things? Thank.
Asked
Active
Viewed 354 times
2 Answers
2
you can set UIInterpolatingMotionEffect
x and y ordination with help of UIMotionEffectGroup
. I just test one code in to my demo and i put this here check this:-
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = self.view.bounds;
for (NSInteger i=0; i<1; i++) {
CGFloat left = (frame.size.width-100)/2+i%2*10;
CGFloat top = (frame.size.height-100)/2+i%3*10;
UIImageView *demoView = [[UIImageView alloc] initWithFrame:CGRectMake(left, top , 100, 100)];
[demoView setImage:[UIImage imageNamed:@"FA4nH.jpg"]];
// demoView.backgroundColor = [UIColor colorWithRed:i/12.0f green:i/18.0f blue:i/24.0f alpha:0.8];
[self.view addSubview:demoView];
UIInterpolatingMotionEffect *xAxis = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
UIInterpolatingMotionEffect *yAxis = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
left += i*50;
top += i *50;
xAxis.minimumRelativeValue = @(-left);
xAxis.maximumRelativeValue = @(left);
yAxis.minimumRelativeValue = @(-top);
yAxis.maximumRelativeValue = @(top);
UIMotionEffectGroup *motionEffectGroup = [[UIMotionEffectGroup alloc] init];
motionEffectGroup.motionEffects = @[xAxis, yAxis];
[demoView addMotionEffect:motionEffectGroup];
}
}
Check this in to real Device that work nice i tested this in to my one of the demo project. hope that helps to you.

Nitin Gohel
- 49,482
- 17
- 105
- 144
0
in iOS 7 you have UIMotionEffect.
Another user in Stackoverflow ask a similar question. You can read here: Solution to parallax effect in iOS 7
Also you can take a look to this library in GitHub: NGAParallaxMotion. Basically is a tiny category that help you to achieve a parallax effect with UIMotionEffect.

Community
- 1
- 1

Carlos Jiménez
- 527
- 5
- 15