Why the animation of KeyboardDismissMode is weird - ios

I add this code to enable scroll to dismiss keyboard
tableView.keyboardDismissMode = .onDrag
But the keyboard always lose the animation when it was about to exit,
like at this position
Reference Image
iOS version is 14.4

You can dismiss your keyboard when you scroll with simply using UIScrollViewDelegate method scrollViewDidScroll like below:
extension yourClass: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
self.searchbar.resignFirstResponder() // Your textField or searchBar etc.
}
}

Related

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)
}

UIScrollView Delegate Re-Routing - To check the state of UIScrollView

I have a tableView and button on the same view (Siblings),
i need to HIDE the button when the tableView is SCROLLING (Up and Down Direction no problem) and SHOW when it is STOPPED SCROLLING
I tried the following code, but it is not working (Correctly)
func scrollViewDidScroll(_ scrollView: UIScrollView) {
self.vcView.hideButton()
}
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
self.vcView.showButton();
}
After a lot of search i found this article, but it is in Objective C, can anyone help me to convert it in to Swift 3.
Why not simply implement these two delegate methods:
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
self.vcView.hideButton()
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
self.vcView.showButton();
}
If you're only looking to show and hide a button or any view while scrolling, this will work. Just be sure to set the scrollview delegate and it should work without issues.
Theres no need to convert that objc code to swift.
https://screencast.com/t/eTq9Nzfsgs6E

How to hide a UIButton during textView scrolling

I am making an iOS app which contains a detailed text under UITextView.I added a share button in the view beside a UITextView. I want the button to be hidden when the user starts scrolling and return back when scrolling is not detected.
What I did was this...
if(detailDescriptionTextView.isScrollEnabled == true)
{my button.isHidden = true }
The above code hides the button entirely since scrollview is on by default. So what shall I do?
As of UITextView inherits from UIScrollView you can use UIScrollViewDelegate method for this purpose. You need to just set the delegate of UITextView and implement below methods of UIScrollViewDelegate and you all set to go.
func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
if yourTextView = scrollView {
yourButton.isHidden = true
}
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if yourTextView = scrollView {
yourButton.isHidden = false
}
}
UITextView is a UIScrollView subclass. Therefore the UIScrollView delegate method you are using is also available when using UITextView.
you should use scrollViewDidScroll to detect scroll
func scrollViewDidScroll(_ scrollView: UIScrollView) {
button.isHidden = true
}
You can use scrollViewDidEndDecelerating . It will call when textView stop scrolling.
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
button.isHidden = false
}

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
}

How to override the handlePan selector in UICollectionView

In my tvOS app, I am trying to listen to changes in scrolling of my UICollectionView. After research, I found that the collection view natively receives a few gesture recognizers among them a UIPanGestureRecognizer with the selector handlePan:
<UIScrollViewPanGestureRecognizer: 0x101a4c1a0; state = Possible; delaysTouchesEnded = NO; view = <UICollectionView 0x1020c5d00>; target= <(action=handlePan:, target=<UICollectionView 0x1020c5d00>)>>
in the log, or in code:
myCollectionView.panGestureRecognizer
I was wondering if there's a way to add my controller as the target of the gesture recognizer, or maybe override the handlePan method.
I tried implementing the UIGestureRecognizerDelegate but it does not give me an access to the handlePan method.
Maybe I should just add a custom UIPanGestureRecognizer of my own on the collection view?
UICollectionView is a subclass of UIScrollView so you can detect scroll changes on collectionview by adding scrollview delegates.
Objective-C
// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
}
// called when scroll view grinds to a halt
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
}
Swift
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
}

Resources