Draw beautiful diagram effortlessly on ipad. Click here to know more..

Wednesday, March 28, 2012

Making the iOS text field/view visible which is located under keyboard


The text view being hidden by keyboard is a very common issue faced by iPhone/iPad developers. When you touch a text view, the text view becomes first responder and keyboard automatically appears. If the text view is lying somewhere in lower part of the screen, most probably it will get hidden under the keyboard. The solution is to scroll the text view up enough so that it comes above the keyboard. To do that, you need to add the text view in UIScrollView so that it can be scrolled up.
Here is the strategy:
  • Whenever keyboard appear, check if it is hiding the text view or not.
  • If it is hiding the text view, then scroll the text view up so that it becomes visible.
  • When the keyboard disappears, then scroll the text view to its original position.
Here is the sample code (similar code used in Lekh Diagram):

First register for the keyboard appearing/disappearing event:
[[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(keyboardWasShown:)
            name:UIKeyboardDidShowNotification object:nil];
    
[[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(keyboardWillBeHidden:)
            name:UIKeyboardWillHideNotification object:nil];
The handler for the keyboard appearing event:
- (void)keyboardWasShown:(NSNotification*)aNotification {
    
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    // get the keyboard height
    double keyboardHeight = kbSize.height;
    UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    
    // The calculations are little different for landscape mode.
    if (UIInterfaceOrientationLandscapeLeft == currentOrientation ||UIInterfaceOrientationLandscapeRight == currentOrientation ) {
        keyboardHeight = kbSize.width;
    }
    
    // save the position of the scroll view, so that we can scroll it to its original position when keyboard disappears.
    originalScrollOffset = scroller.contentOffset;

    CGPoint cp = [editView convertPoint:editView.bounds.origin toView:[UIApplicationsharedApplication].keyWindow.rootViewController.view];
    
    cp.y += editView.frame.size.height;
        
    CGRect bounds = [[UIScreen mainScreen] applicationFrame];
    double sh = bounds.size.height;
        
    UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
        
    if (UIInterfaceOrientationLandscapeLeft == currentOrientation ||UIInterfaceOrientationLandscapeRight == currentOrientation ) {
        sh = bounds.size.width;
    }

    // scroll if the keyboard is hiding the text view
    if(cp.y > sh - keyboardHeight){
        double sofset = cp.y - (sh - keyboardHeight);
        CGPoint offset = scroller.contentOffset;
        offset.y += sofset;
        scroller.contentOffset = offset;
    }
}

And when the keyboard disappears:
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
    // restore the scroll position
    scroller.contentOffset = originalScrollOffset;
}


The above code is used in "Lekh Diagram" ipad app. Lekh Diagrma is a sketch recognition diagramming app.
You can get the Lekh Diagram from app store:
https://itunes.apple.com/us/app/lekh-diagram/id576124115

You can see how content in scrolled when the keyboard appears in the demo of Lekh Diagram:


Learn more about Lekh Diagram: http://www.avabodh.com/lekh

83 comments:

  1. Note for googlers: visit the link below
    http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present/21096604#21096604

    ReplyDelete
    Replies
    1. Forming a wonderful art and including a case in your drawing surface with the Mixtiles promo code frame. Drawing your bright environment and showing the skills as an artist. The designer or artist is a unique person that is different from others.

      Delete
  2. Good post. Speaking about technologies these days. All of the paperwork is left behind and now it is time to go virtual. Read about data room m&a and it will make sense to you.

    ReplyDelete
  3. In my opinion, such researches will help you in the future. You can answer your children when they ask about family, etc. More over, you can help them with doing homework using https://domyhomework.guru/blog/make-homework-fun

    ReplyDelete
  4. This some way or another is turning obliterating as a great part of the street conflicts are happening because of the utilization of TWD. To illuminate this inconvenience, versatile organizations are concocting Audio text message include which is making it advantageous to connect while driving even while texting.program that reads text

    ReplyDelete
  5. Often this was met with slightly blank expressions - and rightly so as not many translation service providers would lay claim to offering poor quality translations. Technical Translation service

    ReplyDelete
  6. This is colossally and superfluously tedious. You ought to most likely respite and begin again effectively, anytime in the record, and whenever, effortlessly. text to speech recorder

    ReplyDelete
  7. خدمات تشمل جميع أركان تنظيف المنزل للحمامات والمطابخ تنظيف السجاد والأريكة بالإضافة إلى تنظيف وتطهير البلاط والأرضيات شركة النجوم لخدمات التنظيف
    شركة تنظيف فلل بجدة
    شركة تنظيف بيوت بجدة
    شركة تنظيف شقق بجدة

    ReplyDelete
  8. Sounds interesting enough; maybe I'll watch out for this. with free guilds and quests

    ReplyDelete
  9. https://hmzapc.com/fl-studio-cracked-download-here/
    FL Studio Crack is exclusive software. The software is used for Latest Music Creations. Its previous name is Fruity-loops. It’s a full product atmosphere or Latest Music Creations (LMC). Serving more further than 18 years of latest built. That provides everything.

    ReplyDelete
  10. https://cracksoon.com/mcafee-antivirus-crack-key-full-download/
    Cracked Here is a useful place where you can easily find Activators, Patch, Full version software Free Download, License key, serial key, keygen, Activation Key and Torrents. Get all of these by easily just on a single click.

    ReplyDelete
  11. https://crackpluskey.com/autodesk-3d-max-crack-key-2020-here/
    Autodesk 3ds Max Crack is the modelling and rendering software. Which is design for visualization, games and animations software? The 3d Max offers a flexible and rich toolset for the users that the user creates the premium design for full aristocratic control view. Therefore it creates a massive new world in the games industry. It gives high-quality visualization to architect workers. It models final interiors and all kind of objects which is used in them

    ReplyDelete
  12. A text field is a single-line, fixed-height field, often with rounded corners, that automatically brings up a keyboard when the user taps it in Check us out

    ReplyDelete
  13. When I was still in school, I used the services of my assistants and chose this site https://payforessay.net/, which I often visited for writing work, which got the job done quickly and efficiently.

    ReplyDelete
  14. Dependably my best memories were just about playing in the casino. By and by, paying little psyche to whatever else I like to give bier haus slots different games a shot the web. You can get an enormous stack of money in a casino if you sort out some way to deal with play. In like way, I can help you and give you marvelous tips on the most talented procedure to play conclusively in a casino

    ReplyDelete
  15. Presently many new companies are opening everywhere on the world, this can straightforwardly be known as the hundred years of new businesses, since all that can go to our brains we can carry out, having, obviously, a decent group of trained professionals and some sort of start-up capital. In each startup, a group of designers is vital, who will completely submerge themselves simultaneously and do all that could be within reach to guarantee that your startup is completely figured it out. Consistently an ever increasing number of organizations show up in any market, in any of their varieties. When beginning a totally new business, recruiting a whole group on the double is very expensive and risky, so you need to search for alternate approaches to communicate with the labor force. Recruiting a backbone js specialist for a recently taught business assumes a vital part later on result, so a positive result can be impacted from the beginning. A solid individual who comprehends everything being developed for a startup is critical, he is liable for the specialized execution. Practically all advanced new companies are computerized, so discovering web designers for them is turning into the fundamental assignment. In the event that you have a decent engineer, you will have an exceptionally brisk beginning, expanded creation, great quality.

    ReplyDelete
  16. Letasoft Sound Booster Crack
    Letasoft Sound Booster Crack is software that will amplify sound volume to a brand new extent. It’s specifically useful for those wherever the system is supplied with larger music system capacities.

    ReplyDelete
  17. Camtasia Studio Crack
    Camtasia Studio Crack is the best tool and facilitates the software for the records the screen and video editing. Therefore this tool is much professional and the best quality of software that has friendly and easy to use.

    ReplyDelete
  18. FL Studio Crack
    FL Studio Crack provides the facility of creating the best and superb music ever. On the other hand, people can use it to produce the best collection of audio sounds.

    ReplyDelete
  19. Virtual DJ Build Crack
    Virtual DJ Build Crack is a powerful software that you can utilize for music and also for video mixing. This software is based on nearly all the abilities. That use of music and video quality enhancing.

    ReplyDelete
  20. Aster v7 Crack
    Aster v7 Crack could be your stage which transforms your own system to a multiuser channel. It is two or even more users to manually function on the personal computer at the same time. The particular settings lets multiple end-users to make use of a pc for someone stage.

    ReplyDelete
  21. I really like your content. Your post is really informative. I have learned a lot from your article and I’m looking forward to applying it in my article given below!.
    OriginCrack
    vstcrackss.com
    TubeDigger Crack Free Download
    Enscape3D Crack Download
    Unity Pro Crack Download
    Idm Crack Download

    ReplyDelete
  22. I wondered for a long time a nice girl I might chase. This issue was funded by a website. They thought of me immediately as the best service for finding slovenian women, who have changed my life for. Slovenian brides have the worry about women living by the sea, but they are much more interesting in their character and beauty. For those who want your love, I propose you. When you know that my new girlfriend is Slovenia, I don't regret using a bride placement services. I advise someone who wants love to have the internet.

    ReplyDelete
  23. Hi! Thanks for this info. Are you interested in crypto trading? On my site you can watch a review of the best telegram channels with crypto signals free.

    ReplyDelete
  24. 3DMark Crack
    3DMark Crack is a custom software of benchmarking for a Mac system. Produce through the Future Mark company. It also looks at the appearance of 3D graphics processing of a Pc. And also scans it to judge its speed.

    ReplyDelete
  25. 3DMark Crack
    3DMark Crack is a special tool that use to measure the gaming performance of PC. It checks the system and hardware capability to make the overall performance. Also, this tool includes all the tools to measure all the device gamming

    ReplyDelete
  26. Wondershare Dr Fone Crack
    Wondershare Dr Fone Crack is the best program, and it will help the users to regain the lost files and information. Further, it can recover information on your devices without any further issues.

    ReplyDelete
  27. Adobe Acrobat Pro DC Crack
    Adobe Acrobat Pro DC Crack is application software. This software enables us to create a view and manage the PDF file easily. The adobe acrobat reader is easily available on the computer system and the mobile phone also.

    ReplyDelete
  28. CCleaner Pro Crack
    CCleaner Pro Crack the best tool for MS Windows to clean out all kinds of junk files. Therefore, it also uses to clean the computer and make the system more smooth. While it also uses to secure the system to make the data secure.

    ReplyDelete
  29. Golden Software Grapher Keygen
    Golden Software Grapher Keygen is a full-featured scientific graphics package, allowing the user to import data in many formats, create and integrate a variety of 2D and 3D graphic types, and customize graphics with unlimited detail.

    ReplyDelete
  30. https://proscrack.co/angry-birds-epic-crack/
    Angry Birds Epic Serial Key was a success because it wowed gamers with great gameplay and unforgettable characters. For this reason, Rovio Entertainment has taken the right step by using its success to create sequels and spin-offs like the Angry Birds Epic RPG. In this game, the birds prepare for a new adventure as they head to Piggy Islands.

    ReplyDelete
  31. The student doesn't have time as they're working as well as studying, so they can't do the best essay they can themselves. Looking to free up your time homework help cpm? Consider the essay writing service! Let's face it; there are not enough hours in the day to write essays.

    ReplyDelete
  32. Toon Boom Harmony’s free download provides design, drawing, and animation tools for young artists with enhanced performance. Provides drawing and animation tools for artists. This Website

    ReplyDelete
  33. 4K Video Downloader crack
    4K Video Downloader Crack is the best and the most powerful software and it comes with proficient features to convert your videos to different formats.

    ReplyDelete
  34. ESET Smart Security Premium
    crack

    this software is the best solution for you to keep your devices healthy. Further, it will allow you to notice and handle the catalog synch and the administrator.

    ReplyDelete
  35. iMyFone LockWiper crack
    this is the latest software that you can use as an unlocker. This application can be used when you sometimes forget any device password.

    ReplyDelete
  36. AVG Internet Security crack
    this is the best and the most powerful software that can help the users you get amazing protection for their devices.

    ReplyDelete
  37. Visual Watermark crack
    this is an efficient and fantastic app, and it is used to add different types of watermarks to your pictures and images

    ReplyDelete
  38. I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I’ve got you bookmarked to look at new stuff you post…
    Moviesflix

    ReplyDelete
  39. Techsmith Camtasia Studio Crack With Serial Key Free Download Techsmith Camtasia Crack is a software suite for creating and manipulating videos in high definition by recording screen activity. However, it is the complete professional solution for recording, editing and sharing high-quality screen video on the Web. CD-ROM and portable media players, including iPod. With support

    ReplyDelete
  40. The crack analyzer data for tonal balance control is based on thousands of tracks of different genres. The algorithm has to parse different songs to obtain average information about the shape of the frequencies in metal, rock, hip-hop, jazz, and other styles. Iztope Tonal Balance Control Crack

    ReplyDelete
  41. Appreciation is a wonderful thing...thanks for sharing keep it up.Letasoft Sound Booster Crack

    ReplyDelete
  42. This comment has been removed by the author.

    ReplyDelete
  43. Very wonderful informative article. I appreciated looking at your article. Very wonderful reveal. I would like to twit this on my followers. Many thanks!

    bulletintech
    whizzherald
    talesbuzz
    alternativestips
    techwithgeeks
    shindigweb
    gettechexpert
    taylor olsen

    ReplyDelete
  44. WonderFox DVD Ripper Crack can convert DVD movies to various formats like AVI, MP4, MKV, MPG. Supports popular video formats and types of DVD movies. The software can remove various locks such as CSS, region code, multi-angle, RCE, Sony ARccOS, UOP and Disney X-Project. Ripping a DVD to AVI and 5 to 10 MPG takes about 20 minutes. WonderFox DVD Ripper Crack is simple and only in three steps (Dario DVD selection – search storage and format – start ripping and converting). Despite the high extraction speed, the original quality of your video is preserved. It offers flexible options to adjust and adjust parameters to adjust the output video in terms of video audio coding, bit rate, frame rate, aspect ratio, resolution, audio codec, audio channel number, sampling frequency etc. You can download from this link https://crackclick.com/wonderfox-dvd-ripper-crack/

    ReplyDelete
  45. https://crackedpro.org/wondershare-recoverit-key-2021-cracked/

    Wondershare Recoverit Crack is a powerful and recovery software. Lost data easily recover with the help of this software. So, it is reliable recovery software. It recovers all types of data including image video documents and many more. It provides a user-friendly environment.

    ReplyDelete
  46. https://softscracked.com/automatic-mouse-and-keyboard-crack/

    Automatic Mouse and Keyboard Crack is a good and very useful application which allows you to go the mouse pointer over the road you designate, and also reveal where in fact the click will be produced. Agree, a significant universal opportunity, which can only help to handle a number of very diverse jobs. Suppose you will need to save lots of a whole lot of images from the web

    ReplyDelete
  47. https://crackedhere.com/avg-internet-security-cracked-2019-keys/

    AVG Internet Security 2021 Crack is also known as Anti-Virus Guard and is a family of anti-virus software developed by AVG technologies. This software is available for the windows, android, and macOS, and also provide antivirus protection for all applications. AVG internet security is software that protects all personal devices effectively.

    ReplyDelete
  48. https://activatorskey.com/sublime-text-cracked-plus-keygen/

    Sublime Text is a proprietary cross-platform source code change software. It is introduced by the ‘Jon Skinner’, ‘Will bond’. Sublime Text can operate on Linux, Mac OS X, and Microsoft Windows

    ReplyDelete
  49. Smart Game Booster Crack
    Smart Game Booster Torrent enhances your personal computer even whenever you’re not taking part in any matches, with no remarkable side effects.

    ReplyDelete
  50. EASEUS Partition Master Crack
    EASEUS Partition Master Crack is the wide tool that use to manage the system and other partition of the software.

    ReplyDelete
  51. Wondershare Dr. Fone Crack
    Wondershare Dr. Fone Crack is the perfect software healing software and it helps you to get the best experience.

    ReplyDelete
  52. EaseUS MobiMover Crack
    EaseUS MobiMover Crack acts as the fast app that functions as the data recovery tool for the IOS directory.

    ReplyDelete
  53. Advanced SystemCare Crack
    Advanced SystemCare Crack is a robust program that guarantees the security of your computer. The software is based on the latest integration and monitors computer security.

    ReplyDelete
  54. Apowersoft ApowerMirror Crack
    Apowersoft ApowerMirror Crack is a fantastic and quick program in that you simply may foster the exhibit of Android. While the iOS cellular phone has a personal computer, entirely, a personal person will observe that, and they use it to monitor these cell telephone.

    ReplyDelete
  55. Similarly Crack
    Similarly Crack, the users will be able to get the videos in high HD quality as well as low 3GP quality. Furthermore, the users can even download the video from the online streaming as well. However, it will provide the best experience to the users while they use this software

    ReplyDelete
  56. IObit Malware Fighter Pro Crack
    IObit Malware Fighter Pro Crack is antimalware software. The antimalware that is modern and with it modern tach it helps to kick out any type of malware or virus from every device fastly. This acts as a fighter enemy against malware and viruses.

    ReplyDelete
  57. IBM SPSS Crack
    IBM SPSS Crack is great and all-in-one software for business consumers everywhere. The service offers a range of analytical tools to grow up your business.

    ReplyDelete
  58. Autodesk Maya Crack
    Autodesk Maya Crack is one of the good and very powerful 3D modeling programs where the user can create both static moments and animations. Maya is an easy-to-use program

    ReplyDelete
  59. https://autocracking.com/fl-studio-crack-there-torrent-free/
    FL Studio Crack is a digital audio workstation. This program is available in four different editions for the Microsoft window.

    ReplyDelete
  60. https://greencracks.com/macrium-reflect-crack-torrent-2020/
    Macrium Reflect Torrent is an image recovery and cloning solution software app. It is introduced by the ‘Paramount Software UK Ltd’ in 2006. The program operates on Microsoft Windows. Macrium Reflect generates disk images and file recovery archives.

    ReplyDelete
  61. https://activatorscrack.com/bluesoleil-activation-keys/
    BlueSoleil Crack is an all in one popular and great software that handles the bond between some type of computer and the Bluetooth devices around it. There are plenty of applications, and BlueSoleil offers a program that will easily concentrate on the assistance available with regards to the linked hardware.

    ReplyDelete
  62. https://thepcgamesbox.com/the-elder-scrolls-v-skyrim-pc-game-free-download/
    The Elder Scrolls V: Skyrim Free Download is an action-adventure and role-playing combat-based game. It is 5th main installment of the Elder Scrolls game franchise.

    ReplyDelete
  63. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to Crack But Thankfully, I recently visited a website named Cracked Fine
    3DMark Crack

    ReplyDelete
  64. This website has a wealth of knowledge and information.
    Thank You for sharing us such a nice information and also we will be glad if u Visit our site.
    https://cracksync.com/autodesk-maya-crack/

    ReplyDelete
  65. Really Good Work Done By You...However, stopping by with great quality writing, it's hard to see any good blog today.
    fullzversionpro.org
    cracksoftwarefreedownload.com
    Anni Crack
    WinISO CRACK

    ReplyDelete
  66. Extremely helpful information particularly the last part
    Thanx For Sharing

    ReplyDelete
  67. Really Good Work Done By You...However, stopping by with great quality writing, it's hard to see any good blog today.
    PRCrack
    Bplan Data Recovery Software CRACK

    ReplyDelete
  68. VRay Crack Mac is very helpful to use for professional designers. It makes them able to remove the noise. Many other types of noise ups tools to remove 50 % of noise from the projects as well.
    Click here
    Download Now

    ReplyDelete
  69. Hello, Dear Thanks for sharing such great content with the US it’s really amazing content so please keep sharing. I also have something for you so please check out
    HowToCrack MacOSX

    ReplyDelete
  70. You see, I just always wanted to be closer to my mother. That's why I started a tradition of giving her flowers every Sunday along with cards. Here https://boomf.com/collections/mothers-day-from-bump-cards last time I ordered flower delivery, you can immediately buy original postcards for Mother's Day!

    ReplyDelete
  71. Na przykład jest doskonałe kasyno http://www.indoorkarting.pl/ kasyno online w które zacząłem grać nie tak dawno temu, okazuje się, że wygrywa, najważniejsze jest tutaj przestrzeganie pewnych zasad, a wtedy będzie doskonały dodatkowy dochód, spróbuj tam zagrać , na pewno ci się spodoba.

    ReplyDelete
  72. Hello, Dear Thanks for sharing such great content with the US it’s really amazing content so please keep sharing. I also have something for you so please check out

    HowToCrack AntiVirus

    HowToCrack Pre-Installed Games

    ReplyDelete
  73. PureVPN Crack is a good VPN service that is reliable and easy to use. There are often big discounts on its two-year subscription, making it a good value.
    PUREVPN Crack
    F-SECURE VPN Crack
    PUREVPN Crack
    Flyvpn Crack
    OPENVPN Crack

    ReplyDelete
  74. If you are one of those people who are worried that they have made some mistakes in their paper then you should really look for online help. Having someone proofread and edit your work can help you avoid submitting a paper that's riddled with errors. and this post not everyone has the means to hire an editor to sift through their essays or their reports. but it shouldn't be too much of a problem, especially when there are free sentence correctors online

    ReplyDelete
  75. As the world becomes increasingly digital, the amount of information that we have to manage continues to grow. Data labeling services like pixel annotation offer a solution by providing access to expert teams that can streamline the process and make it much more manageable. For businesses struggling with this issue, online services can help select the ideal team of data labeling professionals.

    ReplyDelete
  76. Seeking essay assignment help can be beneficial for refining your writing skills. Services that specialize in essay assignments offer targeted support, helping students improve their writing techniques and produce high-quality essays.

    ReplyDelete