【问题标题】:fade/show UIButton when scroll down/up向下/向上滚动时淡入/显示 UIButton
【发布时间】:2016-06-11 03:42:22
【问题描述】:

我有一个表格视图。在视图中是 UIButton。我想要向下滚动按钮淡出和滚动停止或向上按钮显示时。

代码:

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

但不能正常工作! 谢谢

【问题讨论】:

    标签: ios objective-c uitableview uibutton scrollview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-26
      • 2014-12-28
      • 2016-01-17
      • 1970-01-01
      • 2023-01-17
      相关资源
      最近更新 更多