Fixed UIImage in UITableView at the top

When I add UIImage at the top of my UITableView with prototype cells, the image will not remain fixed. So when I look at the UITableView at the top, it also scrolls along with it.

Is there any idea to add a UIImage as fixed (non-moving)

Thanks!

+4
source share
4 answers

You need to follow this:

  • Save the base view as a regular UIView.
  • Add image as subView at say (0,10)
  • Add a UITableView at position (0, 10 + margin).
+1
source

UITableView is a subclass of UIScrollView. Therefore, we can use the scrollViewDidScroll method to complete this task.

Fixing imageView at the top is simple. But you need to get a link to your imageView in the scrollViewDidScroll method.

 func scrollViewDidScroll(scrollView: UIScrollView) { if scrollView==self.tableView { var frame = yourImageView.frame if scrollView.contentOffset.y > 0 { frame.origin.y = scrollView.contentOffset.y yourImageView.frame = frame } else if scrollView.contentOffset.y == 0 { frame.origin.y = 0 yourImageView.frame = frame } } } 
+1
source

What you can do is subclass UIView and skip the hit test, thus passing all the touch events to the table view below it, which allows you to use gesture scrolling inside the image without moving it.

In your implementation:

 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { UIView *view = [super hitTest:point withEvent:event]; if (view == self) { view = nil; } return view; } 

Put your UIImageView in the table view, i.e. add it to the table supervisor (make sure that user interaction is enabled, and set the class in the storyboard to your subclass.

0
source

Set the image to a UIImageView or add a UIView to the UITableView header as the background using the following method. Sorry, the code below is for quick, you will also find it for Objective C.

 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { } 
0
source

All Articles