Swift - View inside UIScrollView not touched while scrolling - ios

I have a custom view inside a UIScrollView
Tapping/touching works perfectly if UIScrollView is not scrolling.
However, when it is scrolling, I need to tap the scrollview first to stop the scrolling, then tap again the scrollview to select my custom view.
Upon searching, I ended up with scrollViewDidEndDragging
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if(!decelerate){
print(scrollView.panGestureRecognizer.location(in: scrollView))
//tap scrollview again but now programmatically
}
}
I wanted to tap the scrollview again with the location(CGPoint) where the last tap location is, but couldn't find any way to do it.
But, if you have any idea on touching my custom view inside UIScrollView while scrolling, that would be really great.
Thank you!

Related

UITableView on scrolling up moves from front to behind

Below view is a tableViewController which is implemented and set the delegate and datasource methods and it works perfectly fine but I have no idea how to implement the purple view behavior on scrolling up and down.
How can I implement it?
The below code is the way I detect that view scrolled up or down. but still, no clue to implement this behavior.
override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
let translation = scrollView.panGestureRecognizer.translation(in: scrollView.superview)
if translation.y > 0 {
presenter?.viewScrolledDown()
} else {
presenter?.viewScrolledUp()
}
}
this question covers how to animate a backgroundColor. If the purple view is a UIView, this won't be a problem. It starts behind the tableView and then moves to the front of the tableView. You can handle this by using these functions:
view.bringSubviewToFront(purpleView)
view.sendSubviewToBack(tableView)
You will also need to animate the autoLayout constraints to move the bottom of the purple view up to the top of the tableView.

How to resign textview when UITableView Scrolls

I have created a custom UITableViewCell, and a UITextView was put inside this prototype cell. When I click on this textView, keyboard can bounce automatically. However, if I want to hide the keyboard, I will have to click Return key. It isn't quite convenient.
Here's the question. How can I resign the textView's firstResponder for hiding the keyboard when I scroll the tableview.
Add UITableViewDelegate and add the below method:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
view.endEditing(true)
}

iOS TableView on Scrollview Event Problem

I have a scrollview in a ViewController. The scrollview has a UIScrollViewDelegate.On upon that i am adding a Tableview like below:
self.view.addSubview(self.tableView)
But when i am scrolling on tableview cells somehow the scrollview delegate is getting event, which is unexpected.
What can i do to prevent that?
The UITableView is the subclass of UIScrollView and that is the reason you are getting calls to the UIScrollViewDelegate when you are scrolling the cells.
You can not prevent this if you want to have the scrolling enabled for the TableView. I would suggest you check this condition inside your delegate method, for example:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard scrollView != self.tableView else {return}
}
That's normal because UITableView is a subclass of UIScrollView. Thus you should check if scrollView != self.tableView then do what you want to do inside the scrollView delegate method.

By dragging up and down scrolling tableview, the UIView animation getting halt in iOS

I am doing iOS application. Its like speech translation. For that I am showing animation to UIView with waves like Siri in iPhone, and above that I placed tableview to show text. Its working fine, but the issue is while animation going on, if I drag the scroll up or down in tableview, the UIView animation getting halt and after I stop the dragging, again animation working start.
Its not only happening due to tableview dragging, any other object if I tried to touch and drag the Waves animation getting stopping.
My requirement is it should not stop the animation, even if we click/drag other objects.
Can anyone suggest me how to fix this.
Thanks!
Set ScrollViewDelegate and use these delegate methods:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//Stop Animation of UIView here
}
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
//Start Animation of UIView here
}

Switching to UIPanGestureRecognizer when TableView reaches it top

I have a UITableView added to UIViewController. Behind that TableView there is UIImageView like this:
The default behavior of a UITableView is to show whitespace when scrolling up and there is no more content to show. I would like to override this and switch to custom UIPanGestureRecognizer that will move the whole tableview down.
To clarify: When the tableview reaches it top I would like to move the entire tableview instead.
I have set up my PanGestureRecognizer and added it to the tableview and tried this:
func scrollViewDidScroll(scrollView: UIScrollView) {
if self.tableView.contentOffset.y == 0{ //tableview reaches its top
panGestureRecognizer.enabled = true
}else{
panGestureRecognizer.enabled = false
}
}
This does not work at all since the the scrollViewDidScroll triggers at the end of the gesture.
Any other ideas on how I can implement this?

Resources