-2

I want to create a scrollview which is similar to http://www.nytimes.com/interactive/2015/04/22/magazine/new-york-city-walks.html?smid=tw-nytimes&_r=1 (see link on iPhone and not on web)

I want the user to scroll and then show an image effect like this page. I dont want to place an empty cell in the collection view and have a background image. I want to display some content from third party API which is clickable hence I have to integrate this effect into the scroll view. Any suggestions how this could be achieved?

Abhinav Singh
  • 243
  • 1
  • 13
  • 2
    Just use a `UITableView`. – Michael May 09 '15 at 04:44
  • @nikita Lol. Did you even read the question? – Abhinav Singh May 09 '15 at 04:49
  • 2
    Yeah, what's the problem? There are many options to achieve this...including a `UITableView`. – Michael May 09 '15 at 04:52
  • 2
    [link](http://stackoverflow.com/questions/925115/is-there-a-way-to-remove-the-separator-line-from-a-uitableview) this is how you remove the separator lines in UITableView. You need to create a custom UITableViewCell in Interface Builder. [link](http://stackoverflow.com/questions/8259475/detect-the-current-top-cell-in-a-uitableview-after-scrolling) Then find which table cell is at the top and then show that image effect. – Asdrubal May 09 '15 at 05:05
  • [link] http://stackoverflow.com/questions/1008246/how-to-create-a-uitableviewcell-with-a-transparent-background I know this isn't what you want to do but its definitely the easiest way – Asdrubal May 09 '15 at 05:15
  • @CaligulaOfApps thanks mate for the suggestion. Unfortunately its not what I am looking for but its more like I am trying to create the same scrolling effect which is there. – Abhinav Singh May 09 '15 at 05:17

2 Answers2

2

Yes u can easily achieve this by using tableview, what if the contents are more then it would be memory issue, so better u use tableview by reusing the cells and its content's u can achieve better performance. by subclassing the tableview cell u can customise the appearance and interactions. for example i took a tableview and some long text's assume u are displaying the texts in the cell

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.
  UIFont *labelFont = [UIFont fontWithName:@"Noteworthy-Bold" size:20];
  NSDictionary *arialdict = [NSDictionary dictionaryWithObject:labelFont forKey:NSFontAttributeName];

  array = [NSMutableArray arrayWithObjects:
        @"I want the user to scroll and then show an image effect like this page. I dont want to place an empty cell in the collection view and have a background image. I want to display some content from third party API which is clickable hence I have to integrate this effect into the scroll view. Any suggestions how this could be achieved?",
        @"The drag-and-drop design interface makes creating and updating Passbook passes and Google Wallet cards a snap. Better yet, if you create a pass for Passbook, our system can map the fields over to a corresponding card for Google Wallet, and vice-versa. The visual WYSIWYG editor also lets you preview your design as you go, so you can see the pass or card come to life, and you don't have to spend time sending yourself tests over and over as you build out your program. Choose colors, images, texts fields, and more--without writing a single line of code.",
        @"It's the community...The community forums provide a valuable exchange of knowledge that makes game development faster and more fun for everyone, from new users to industry vets.The user groups…Many of our users find fellow developers and artists to collaborate with through their local Unity user group. Find one near you and get in touch!New services...What happens after you finish your game? How do you find more players, and make enough money to keep doing what you love? Our new services can help!Unity Ads is just one of our new services available that helped Hipster Whale make over a million dollars!Increase the visibility of your game and drive organic installs with Unity Everyplay, a simple service that enables players to seamlessly record and post replay videos directly from inside your game, and share them with their friends and family.", @"I want the user to scroll and then show an image effect like this page. I dont want to place an empty cell in the collection view and have a background image. I want to display some content from third party API which is clickable hence I have to integrate this effect into the scroll view. Any suggestions how this could be achieved?",
        @"The drag-and-drop design interface makes creating and updating Passbook passes and Google Wallet cards a snap. Better yet, if you create a pass for Passbook, our system can map the fields over to a corresponding card for Google Wallet, and vice-versa. The visual WYSIWYG editor also lets you preview your design as you go, so you can see the pass or card come to life, and you don't have to spend time sending yourself tests over and over as you build out your program. Choose colors, images, texts fields, and more--without writing a single line of code.",
        @"It's the community...The community forums provide a valuable exchange of knowledge that makes game development faster and more fun for everyone, from new users to industry vets.The user groups…Many of our users find fellow developers and artists to collaborate with through their local Unity user group. Find one near you and get in touch!New services...What happens after you finish your game? How do you find more players, and make enough money to keep doing what you love? Our new services can help!Unity Ads is just one of our new services available that helped Hipster Whale make over a million dollars!Increase the visibility of your game and drive organic installs with Unity Everyplay, a simple service that enables players to seamlessly record and post replay videos directly from inside your game, and share them with their friends and family.",@"I want the user to scroll and then show an image effect like this page. I dont want to place an empty cell in the collection view and have a background image. I want to display some content from third party API which is clickable hence I have to integrate this effect into the scroll view. Any suggestions how this could be achieved?",
        @"The drag-and-drop design interface makes creating and updating Passbook passes and Google Wallet cards a snap. Better yet, if you create a pass for Passbook, our system can map the fields over to a corresponding card for Google Wallet, and vice-versa. The visual WYSIWYG editor also lets you preview your design as you go, so you can see the pass or card come to life, and you don't have to spend time sending yourself tests over and over as you build out your program. Choose colors, images, texts fields, and more--without writing a single line of code.",
        @"It's the community...The community forums provide a valuable exchange of knowledge that makes game development faster and more fun for everyone, from new users to industry vets.The user groups…Many of our users find fellow developers and artists to collaborate with through their local Unity user group. Find one near you and get in touch!New services...What happens after you finish your game? How do you find more players, and make enough money to keep doing what you love? Our new services can help!Unity Ads is just one of our new services available that helped Hipster Whale make over a million dollars!Increase the visibility of your game and drive organic installs with Unity Everyplay, a simple service that enables players to seamlessly record and post replay videos directly from inside your game, and share them with their friends and family.",@"I want the user to scroll and then show an image effect like this page. I dont want to place an empty cell in the collection view and have a background image. I want to display some content from third party API which is clickable hence I have to integrate this effect into the scroll view. Any suggestions how this could be achieved?",
        @"The drag-and-drop design interface makes creating and updating Passbook passes and Google Wallet cards a snap. Better yet, if you create a pass for Passbook, our system can map the fields over to a corresponding card for Google Wallet, and vice-versa. The visual WYSIWYG editor also lets you preview your design as you go, so you can see the pass or card come to life, and you don't have to spend time sending yourself tests over and over as you build out your program. Choose colors, images, texts fields, and more--without writing a single line of code.",
         @"It's the community...The community forums provide a valuable exchange of knowledge that makes game development faster and more fun for everyone, from new users to industry vets.The user groups…Many of our users find fellow developers and artists to collaborate with through their local Unity user group. Find one near you and get in touch!New services...What happens after you finish your game? How do you find more players, and make enough money to keep doing what you love? Our new services can help!Unity Ads is just one of our new services available that helped Hipster Whale make over a million dollars!Increase the visibility of your game and drive organic installs with Unity Everyplay, a simple service that enables players to seamlessly record and post replay videos directly from inside your game, and share them with their friends and family.",@"I want the user to scroll and then show an image effect like this page. I dont want to place an empty cell in the collection view and have a background image. I want to display some content from third party API which is clickable hence I have to integrate this effect into the scroll view. Any suggestions how this could be achieved?",
         @"The drag-and-drop design interface makes creating and updating Passbook passes and Google Wallet cards a snap. Better yet, if you create a pass for Passbook, our system can map the fields over to a corresponding card for Google Wallet, and vice-versa. The visual WYSIWYG editor also lets you preview your design as you go, so you can see the pass or card come to life, and you don't have to spend time sending yourself tests over and over as you build out your program. Choose colors, images, texts fields, and more--without writing a single line of code.",
         @"It's the community...The community forums provide a valuable exchange of knowledge that makes game development faster and more fun for everyone, from new users to industry vets.The user groups…Many of our users find fellow developers and artists to collaborate with through their local Unity user group. Find one near you and get in touch!New services...What happens after you finish your game? How do you find more players, and make enough money to keep doing what you love? Our new services can help!Unity Ads is just one of our new services available that helped Hipster Whale make over a million dollars!Increase the visibility of your game and drive organic installs with Unity Everyplay, a simple service that enables players to seamlessly record and post replay videos directly from inside your game, and share them with their friends and family.",nil];

 }
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {
   return 1;
 }

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return [array count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  if(Cell == nil)
  {
      Cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  }


  [Cell.textLabel sizeToFit];
  Cell.textLabel.attributedText = [[NSMutableAttributedString alloc] initWithString:[array objectAtIndex:indexPath.row]];
  Cell.textLabel.numberOfLines = 0;
  Cell.textLabel.alpha = 0.0f; //set the label alpha to zero 
  return Cell;
 }

 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
   //hear only u can make cell's contents to visible' make changes to your contents hear, for example if the cells contains map view, buttons ..etc put all in a single view and set its alpha to zero, and in the animation block set it to one similar to below example
  cell.textLabel.alpha = 0.0f;
  [UIView animateWithDuration:3 animations:^{
     cell.textLabel.alpha = 1.0f; //and hear set it to one 
  }];

}

//calculate height of the text
-(float)height :(NSString *)string
{

   NSAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:string];
   CGRect rect = [attributedText boundingRectWithSize:(CGSize){225, MAXFLOAT}
                                           options:NSStringDrawingUsesLineFragmentOrigin
                                           context:nil];
   CGSize requiredSize = rect.size;
   return requiredSize.height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   //whatever the height u need to calculate calculate hear only
   CGFloat heightOfcell = [self height:[array objectAtIndex:indexPath.row]];
   NSLog(@"%f",heightOfcell);
   return heightOfcell + 100;
}  

try out in separate project u will see the effect just put tableview set its datasource and delegate and past the above code and run, result is like in the website

enter image description here

EDIT to look like iPhone website

For this u need to use custom cell, for example,

enter image description here

in this holder is the view which is cover entire content view of cell and it contains another view componentsHolder, this contains all components like buttons, label's etc..

in the above image set the background color to clear

the entire layout is like below

enter image description here

now set the content view and holder - view background color to clear color set componentsHolder-view background color to white color don't change this views background color

and add the image view just behind the tableview, in the controller for example

enter image description here

and set tableview background color to clear color, this backImageView is the image we are going to change its image after each cell appearing in the code, all cells have same height

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {
   return 1;
 }

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
   return [array count];
 }


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     CustomCellTableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
     if(Cell == nil)
     {
        Cell = [[CustomCellTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

     }
     Cell.descriptionLabel.text = [array objectAtIndex:indexPath.row];
     [Cell.descriptionLabel sizeToFit];
     return Cell;
  }

  //hear u can change the image, example i am changing the image randomly in website they are animate the changing the of the image thats all
  - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  {
    //change image hear
    NSInteger randIndex = arc4random() % 2;
    UIImage *aimage = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.jpg",(long)randIndex]];
    _backImageView.image = aimage;
  }

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     return 585.0f; //constant height
 }

final result will be like below,

enter image description here

Shankar BS
  • 8,394
  • 6
  • 41
  • 53
  • Hey Shan! Thanks for the answer. I need like a scrolling effect in which one cell locks and another expands while scrolling upto a certain point and then it starts collapsing again. In this website you see that you see the content, then you see empty cell through which we can see the background and then we see the content again. So I want to replicate the exact same behaviour. Thanks for your answer though. :) – Abhinav Singh May 09 '15 at 06:09
  • 1
    @AbhinavSingh sorry i though it is like website i will edit the code according to iPhone website – Shankar BS May 09 '15 at 06:58
  • Hey Shan! Thanks for the advice. Really nice of you give answer in this much details. However I want to integrate this behaviour into the scrollview so that I display third party content. Thats why I mentioned in the question that I dont want to have a background image and cellspacing or empty cell to just show background image, but rather I want to have this thing integrated into the scroll view. – Abhinav Singh May 10 '15 at 06:51
-1

that is kind of parallax effect. here is some link for that effect link link link hope this will work

Tejas Ardeshna
  • 4,343
  • 2
  • 20
  • 39
  • It is definitely not a parallax effect. Parallax is when the background image scrolls slower than the foreground image. The background image is simply changing. – Michael May 09 '15 at 04:59
  • yeah i know that, but questioner is looking for parallax effect. the web page in new York time can be implement with just background image of table view. – Tejas Ardeshna May 09 '15 at 05:02
  • Nikita please dont comment if you dont understand the question. Thanks tejas for the direction, yes I am looking for this parallax sort of effect. – Abhinav Singh May 09 '15 at 05:09
  • 3
    @AbhinavSingh You will get more help if you aren't rude. The web page you linked to isn't a parallax effect and can be achieved with a `UITableView`. If you properly ask a question the community will be better able to help you find a solution. – Michael May 09 '15 at 05:12
  • Did I say its a parallax effect? Both of us are saying its a similar effect. I have been doing iOS development for 4 years. I know how to use a freaking table view. See the link in iPhone and please read the question. I hate freeloaders who just want to comment to get some reputation points. – Abhinav Singh May 09 '15 at 05:15
  • 2
    @AbhinavSingh Commenting doesn't increase reputation. – Michael May 09 '15 at 09:37