Advertisement
Joze

Path's parallax

Mar 5th, 2012
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define TAG_FOTO_HEADER 1
  2.  
  3. -(void)parallaxForHeaderScrollView:(UIScrollView *)scrollView
  4. {
  5.     UIView *v = self.tableView.tableHeaderView;
  6.     UIImageView *i = (UIImageView *) [v viewWithTag:TAG_FOTO_HEADER];
  7.    
  8.     CGFloat y = -scrollView.contentOffset.y;
  9.     if (y<0) return;
  10.    
  11.     CGRect fV = v.frame;
  12.     fV.size.height = 150 + y;
  13.     fV.origin.y = -y;
  14.     [v setFrame:fV];
  15.     [v setClipsToBounds:YES];
  16.    
  17.    
  18.     //Parallax
  19.     CGRect f = CGRectMake(0.0f, -170.0f, 320.0f, 320.0f);
  20.     f.origin.y += y / 0.75f;
  21.     [i setFrame:f];    
  22. }
  23.  
  24. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  25. {
  26.     [self parallaxForHeaderScrollView:scrollView];
  27.  
  28. }
  29.  
  30. - (UIView *)configureTop
  31. {
  32.     UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 150.0f)] autorelease];
  33.     UIImageView *t = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, -170.0f, 320.0f, 320.0f)];
  34.     t.image = [UIImage imageNamed:@"the_name_of_the_background_image.jpg"]; //Put your image here
  35.     [view addSubview:t];
  36.     [t setTag:TAG_FOTO_HEADER];
  37.    
  38.     [iZ3Tools setShadowToView:t WithOffset:CGSizeMake(0.0f, -2.0f) WithColor:[UIColor blackColor] WithRadius:0.2f WithOpacity:0.75f];
  39.     [view setBackgroundColor:[UIColor grayColor]];
  40.  
  41.     //Put more elements on your header here
  42.  
  43.     return view;
  44. }
  45.  
  46. - (void)viewDidLoad
  47. {
  48.     [super viewDidLoad];
  49.     // Do any additional setup after loading the view, typically from a nib.
  50.     // Set up the edit and add buttons.
  51.  
  52.     [self.tableView setTableHeaderView:[self configureTop]];
  53.     [self.tableView setBounces:YES];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement