2014-03-14 7 views
2

iOS 7 홈 스크린은 사용자가 장치를 움직일 때 배경이 움직이는 것처럼 시각적 인 기능을 수행 할 수 있습니다. 신청서에서 비슷한 것을 어떻게 할 수 있습니까? 두 개의 이미지 뷰가 있다고 가정 해 보겠습니다. 하나는 다른 것의 위에 있습니다. 비슷한 것을 구현하는 방법? 감사.사용자가 iOS 기기를 이동할 때 백그라운드 변경 시점을 구현하는 방법은 무엇입니까?

답변

0

, iOS 7이 UIMotionEffect입니다.

Stackoverflow의 다른 사용자도 비슷한 질문을합니다. 여기에서 읽을 수 있습니다 : Solution to parallax effect in iOS 7

또한이 라이브러리를 GitHub : NGAParallaxMotion에서 살펴볼 수 있습니다. 기본적으로 UIMotionEffect로 시차 효과를 얻는 데 도움이되는 작은 카테고리입니다.

2

UIInterpolatingMotionEffectx 및 y ordination은 UIMotionEffectGroup입니다. 난 그냥 내 데모에 하나 개의 코드를 테스트하고 난이 여기를 확인 넣어 : -

- (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]; 
     } 

} 

확인이 데모 프로젝트 내 하나에 내가이 시험 좋은 일을 실제 장치에있다. 당신에게 도움이되는 희망.