向下/向上滚动时显示/显示UIButton

时间:2016-02-27 23:44:00

标签: ios objective-c uitableview uibutton scrollview

我有一个tableView。在视图上是UIButton。我希望当向下滚动按钮淡出时以及滚动停止或向上按钮显示时。

enter image description here

代码:

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

但不能正常工作! 感谢

1 个答案:

答案 0 :(得分:1)

你使用的是错误的方法。代替 scrollViewWillBeginDecelerating:使用scrollViewDidScroll:并根据滚动视图的contentOffset更新按钮字母和位置。