floating UIButton with image on a UITableview [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 11:56:53

You can implement the scrollViewDidScroll delegate to change your floating button y origin while the user scroll the table, so that the button will float and stay at the same location.

There is a great example in WWDC 2011 session 125 that does exactly what you want.

In general, you need to save the original y origin of the button after you create it, or you can do it in viewDidLoad, then implement the scrollViewDidScroll and update the button frame.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGRect tableBounds = self.tableView.bounds;
    CGRect floatingButtonFrame = self.floatingButton.frame;
    floatingButtonFrame.origin.y = self.originalOrigin + tableBounds.origin.y;
    self.floatingButton.frame = floatingButtonFrame;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!