The iPad split-keyboard and (missing) Specifications

Source: Internet
Author: User
The iPad split-keyboard and (missing) icationsposposted on May 19,201 2

Developing an app that people actually use is a great way to discover holes in your knowlege of new APIs. I recently released a side project of mine for sale on the app store under the name onepad. it's an electronic pocket notebook that syncs using your iCloud account. it's also a universal app, the first I 've built, and even with a relatively simple app like this there are subtle differences in the two platforms that can catch you off-guard if you're not looking for them.

During the last round of beta testing, one of my testers reported that the interface wasn't updating properly on the iPad in response to Keyboard Events. this is not the kind of person who wocould make frivolous claims but even following his steps everything worked fine for me. luckily, after I let him know of my inability to reproduce the issue, he was kind enough to send me a quick video of the Bug occuring on his device and about 1 second into the video it was clear what the problem was and why I couldn't reproduce it.

He was using the split keyboard.

This new feature, added in iOS 5, allows you to either "undock" the full size keyboard from the bottom of the screen, or slide it up and "split it" into two halves to make thumb typing easier. it was also a feature that I never used, and to be honest, had forgotten even existed soon after the initial, "Hey, that's kind of neat" reaction wore off.

It turns out that when the keyboard is "undocked", as they say, your app no longer has es the standard keyboardwill/didhide/show events. because I was relying on these events to let me know when and how to configure the UI based on the presence of the keyboard, things were getting out of sync.

With the cause of the problem established, I had only to figure out how to replicate these events when using the undocked keyboard. reviewing the uiwindow class reference it was clear that the undocked keyboard handled UI events a little differently. instead of separate show/hide events it offered separate will/didchangeframe events triggered by both user interaction and other application events. this was a start but there was no direct way to map these events to the show/hide events my application relied on.

The solution I settled on, and one that seems to work well, is to compare the destination frame from the keyboarddidchangeframe event's notification to the view's frame and check for an intersection. if the keyboard is visible, it shoshould intersect with the views frame right?

First we need to register for the keyboarddidchangeframe event:

[[Nsnotificationcenter Defacenter Center] Addobserver:SelfSelector:@ Selector(Keyboarddidchangeframe:)Name:UikeyboarddidchangeframenotificationObject:Nil];

Then we just need to pull out the destination frame of the keyboard, convert it's coordinates to our own, and look for an intersection:

 -   (  Void )  Keyboarddidchangeframe  :  (  Nsnotification   *  )  Notification  {      Cgrect   Keyboardendframe  ;      [[  Notification  .  Userinfo   Objectforkey  :  Uikeyboardframeenduserinfokey  ]   Getvalue  :& Keyboardendframe  ];      Cgrect   Keyboardframe   =   [  Self  .  View   Convertrect  :  Keyboardendframe   Fromview  :  Nil  ];      If   (  Cgrectintersectsrect  (  Keyboardframe  ,   Self .  View  .  Frame  ))   {          // Keyboard is visible      }   Else   {          // Keyboard is hidden      }  } 

So if your app supports the iPad and relies on Keyboard Events, be sure to test it with the keyboard undocked. it's one of those problems that's far easier to fix than to discover.

And if you're in the market for a unique notebook/journaling app for iPhone, iPad and iPod touch, I hope you'll take a look at onepad.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.