2016-02-27 31 views
1

我有一個tableView。在視圖上是UIButton。我希望當向下滾動按鈕淡入淡出,當滾動停止或向上按鈕顯示。淡入淡出/向上滾動顯示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

您正在使用錯誤的方法。而不是 scrollViewWillBeginDecelerating:使用scrollViewDidScroll:並更新按鈕alpha和位置基於滾動視圖的contentOffset