UIScrollView: Keyboard dismiss interactively - ios

In the above image the top bar is a custom view which I used like whats app application. Keyboard will dismiss interactively with UIScrollView. I have implemented UIKeyboardWillHideNotification and UIKeyboardDidChangeFrameNotification to move up and down that view. Now the problem is as I used keyboard will dismiss interactively so when user drag his finger to keyboard, it start move up or down accordingly. But I am not able to get any kind of notification to move up or down the view as well.

While I was searching on this matter, I found three different approaches to achieve this.
The easiest is by attaching that custom bar as an input accessory view https://developer.apple.com/documentation/uikit/uiresponder/1621119-inputaccessoryview
You can also attach a dummy view as an input accessory view which emits information about its current location, as described here: https://github.com/brynbodayle/BABFrameObservingInputAccessoryView
Other, the least favourable is to hide the keyboard without any animations and show a captured keyboard static image animating instead, as described here: https://medium.com/#superpeteblaze/ios-custom-keyboard-dismissal-with-swift-9b6df2d9cc49

The keyboard follows the dragging touch offscreen, and can be pulled upward again to cancel the dismiss.
scrollView.keyboardDismissMode = .Interactive
see the Documentation UIScrollViewKeyboardDismissModeInteractive
hope its helpful

Related

iOS - Swift - How to display UIAlertViewController without disabling background

I wanted to display a Popup view on top of the screen but while enabling the actual screen as well. User should be able to perform all touch actions on the screen's controller while displaying and allowing touch actions on popup view as well. No fade for background ofcourse.
I do not see a existing style for UIAlertController that meets this need.
Is it possible with UIAlertController?
(PS. with UIPopoverPresentationController Custom style, managed to disable fade but still couldn't get the touch controls work on background screen)
Sounds like you might want to look into passthroughViews property on UIPopoverPresentationController. From the documentation:
"When displayed, taps outside of the popover window cause the popover to be dismissed automatically. To allow the user to interact with the specified views and not dismiss the popover, you can assign one or more views to the passthroughViews property."
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverController_class/

UIPopoverController Button, Prevent Dimming Overlay?

When presenting a UIPopoverController from a UIButton the entire screen behind the popover is dimmed.
Is it possible in some way or another to prevent the presenting button (the one pressed to show the popover) from being dimmed?
I remember solving this problem when it has appeared the first time on iOS 7. The only solution (if nothing has changed) has 3 parts:
Remove the default background (setting popoverBackgroundViewClass).
Add your own background (I used a subclass of UIPopoverController to handle the appearance callbacks)
Display your button (or any other passthrough views) above the background. You can either remove them from their hierarchy and move them to the same position in the background or just take a screenshot of them and add them to the background.
In the end it's not too difficult but it takes time to debug.

Why iOS default did not support auto keyboard dismiss function?

while I develop iOS application with swift, I wondered why apple did not support auto-dismiss keyboard function in application. This means if I implement a TextLabel on screen, I tapped that label, Keyboard appears, but did not dismissed automatically.
I thought many of application keyboards need to dismissed when users tap on outside of the keyboard screen or click 'done' button on a screen. However, basically, I have to implement keyboard dismiss function on every ViewController. And I think this is code duplication.
Anyone can explain me about apple's application method implementation philosophy and how can I wrote an reusable function, which is not duplicated function in every ViewController scheme.
Transposed from Comments:
In general apps where the main function utilizes the keyboard would rather control when the keyboard dismisses themselves instead on relying on an auto feature.
Ex: For a texting app after I click the send button I would like to send another text. Then I shouldn't dismiss the keyboard.
If you are dismissing the keyboard multiple times than I would try making a view controller class that handles that and subclass it. You can observe when the keyboard is shown and add a button on top of your view so when it is clicked the keyboard dismisses using [self.view endEditing:YES];

iOS popover with a close button outside

I need to create below thing
Currently i'm using WYPopover , but I can't create the button since it's outside of the popover. Is there any existing solution out there ? Many thanks
Create a bigger popover UIView holding all your child elements (current popover + button) and make its background transparent or however you wish.
Popover-controller's are exclusively used in iPad. If you want to use in iPhone, you should create it in a custom way.
I am not familiar with the XYPopover in Github, but normally the custom created popover should be dismissed whenever the user taps any place in the screen. That is one of the key feature of the popovers.
Normally the custom popovers are build like, adding a hidden parent view and then the visible image of a popover frame on it.
You should to do the following,
Avoid dismissing the parent view on tap of parent-hidden-view.
Add a close button at the area where you want to show the close button, on top of the parent-hidden-view.
Capture the button click and dismiss the view (remove the view from superview)
How to customize your need
Creating custom popover view is not a big task. It will take maxim one day, try it your self.
One Parent view with clear color
One background image of a popover frame.
View-inside popover (this needs to be customized for UIPopover also).
Close button.

iOS : Swipe Gesture Push in one ViewController?

I want to add two swipe gesture. I did the code, and it's running, my text in the viewcontroller change when i touch the screen.
BUT, i want to add a "effect" when the user wants to slide at the next (or the previous) news, because currently, i'm just changing the text.
i tried to add action in the storyboard, to add push on the swipe with the view.
It's running, but there are two problems :
The push, seems to have a problem, because, when i want to slide on the previous news, the push effect comes right to left. (and not left - right)
I can't only change the contents without touch the navigation bar ? (because when i slide, the navigation bar loose him title, etc..)
If I understood you correctly you might want to use a UIScrollView. This will give you a nice animation.
You need a UIScrollView and add two of your ViewControllers as subviews.
Here are links to some ScollView tutorials:
Are there any good UIScrollView Tutorials on the net?
Pushing on the navigation controller stack is to the right if you want to go back to opposite direction instead of pushing, you should pop like so: [self.navigationController popViewControllerAnimated:YES]; You could paste some code in your question :)

Resources