Ios 向下/向上滚动时的淡入/显示按钮

Ios 向下/向上滚动时的淡入/显示按钮,ios,objective-c,uitableview,uibutton,scrollview,Ios,Objective C,Uitableview,Uibutton,Scrollview,我有一个桌面视图。“打开视图”按钮。我想当向下滚动按钮淡入淡出,当滚动停止或向上按钮显示 代码: 但是不能正常工作! 谢谢您使用了错误的方法。而不是 ScrollViewWillBeginDelegrating:使用scrollViewDidScroll:并根据滚动视图的contentOffset更新按钮alpha和位置 - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ NSLog(@"Start scrol

我有一个桌面视图。“打开视图”按钮。我想当向下滚动按钮淡入淡出,当滚动停止或向上按钮显示

代码:

但是不能正常工作!
谢谢

您使用了错误的方法。而不是
ScrollViewWillBeginDelegrating:
使用
scrollViewDidScroll:
并根据滚动视图的
contentOffset
更新按钮alpha和位置

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