Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fade/show UIButton when scroll down/up

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

like image 953
Sina Avatar asked Aug 10 '26 02:08

Sina


1 Answers

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

like image 64
Rafa de King Avatar answered Aug 12 '26 22:08

Rafa de King



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!