3

I have a tableView. on view is UIButton. i want when scroll down button fade and when scroll stop or up button show.

enter image description here

code:

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
NSLog(@"Start scroll");

//I assume the buttons are within your cells so you will have to enable them within your cells so you will probably have to handle this by sending a custom message to your cells or accessing them with properties.
CGRect frame = addCommentBtn.frame;
frame.origin.y = scrollView.contentOffset.y + self.newsTableView.frame.size.height  + 4;
addCommentBtn.frame = frame;

[self.view bringSubviewToFront:addCommentBtn];}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSLog(@"End scroll");

// do the same to enable them back
CGRect frame = addCommentBtn.frame;
frame.origin.y = scrollView.contentOffset.y + self.newsTableView.frame.size.height  + 4;
addCommentBtn.frame = frame;

[self.view bringSubviewToFront:addCommentBtn];}

but don't work correctly! Thanks

Sina
  • 849
  • 9
  • 21

1 Answers1

1

You are using wrong method. Instead of scrollViewWillBeginDecelerating: use scrollViewDidScroll: and update button alpha and position based on contentOffset of the scroll view.

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143