Corona SDK - native textfield within scrollview? - coronasdk

In Corona SDK, I'm looking for an example/tutorial of something that seems like it should be incredibly basic: including a text input field within a scrollview.
I have been using widget.newScrollView() for the scrollview, and native.newTextField() for the text input field. The problem, of course, is that the "native" objects exist outside the Corona display object hierarchy, so the textfield can't be placed inside the scrollview and scrolled that way.
A comment on this Corona Labs blog post suggests the technique of using a placeholder image that looks like a textfield, with a touch listener that overlays the real textfield when the user touches it. Is that the best approach to take?

"Faking it" is a proven method of getting stuff done when programming, whether you're using Corona SDK or anything else. While it's nice not to have to jump through hoops to get something done, sometimes it's just the best way to handle it.
In this case, I think using a placeholder is probably the best way to go. You could create a function that uses display.newRect to create the frame of the fake textfield and then display.newText to put in the default and/or user-supplied text.
Something like:
local dObj = showFauxTextfield(x, y, width, height, str)
Create the rect and text according to the parameters passed in, put them into a display group, and pass that back to the calling code. You can then put that into your regular display group along with everything else.
Inside showFauxTextfield() you'll create an event handler that pops up a native.newTextField when it's touched.
It's a little extra work, but Corona typically saves you a lot of dev time anyway, so you'll probably still come out ahead. ;)

If you aren't keen on implementing the placeholder technique mentioned in this post you could always use the WidgetCandy library (http://www.x-pressive.com/WidgetCandy_Corona/). It includes a text field class that will provide similar functionality.

Related

Output specific images when user taps the keyboard

I want to output a image when a user taps on the keyboard. Let's say the user taps A on the keyboard in a UITextView. Instead of outputting the normal A, I want to output the picture of an Ape.
If a user taps "S" I want to output the image of a sun. Is this possible with out having to make a customized keyboard?
Besides creating a custom keyboard yourself, there isn't really a neat method to getting an image output.
One thing you could do is program Swift to automatically recognise the letter input and display an image over or replacing the letter as a result.
To do this, assign a variable to your editable UITextView or UITextField. If you are using XCode you can do this by control-dragging the text field into your code and it will automatically create a weak var, but you can change the strength in the pop up box that appears.
Since you now have a variable, there are two options as to how you display the image. One way is rather boring and will clutter your code, but essentially involves this, which I have simplified for the purposes of demonstration:
if UITextInput == a {
// add image
}
You would have to repeat this for every letter of the alphabet.
Or you could create a dictionary in which each letter corresponds to each image, and find a way to cycle through them, depending on the user's input. Even though this is harder to program for a newbie, it makes the code much neater and quicker.
This is the link to the official Apple documentation on dictionaries:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html#//apple_ref/doc/uid/TP40014097-CH8-ID113
However, since I assume you are programming an app for the younger market, I would recommend creating a custom keyboard as it will be easier in the long run.
Hope this helps,
will

How can I get the size of the keyboard on iPhone?

I want to get the keyboard size without using NSNotification. When I press the plus button, it can replace the keyboard with a custom UIView like this:
Then the plus button is pressed and the view loaded:
How can I achieve this?
I already made same rookie mistake like you want to do here. The problem is you will write a lot only to realize you do not want to avoid standard flow provided you by iOS team. For example you will definitely have a bad time dealing with issue like this one (there is additional bar which is part of standard keyboard for Chinese locale):
I solved this by using other people's work from DAKeyboardControl project. You do not need to attach observer (or if you use DAKeyboardControl - block) directly to your bar with buttons, but to your controller and check what user is trying to do and animate this bar accordingly. In the sources you can see how to get keyboard's animation duration and timing function. It may sound more complicated than it indeed is, just give it a try.

How to draw caret in the scroll view on iOS using system API?

I am working on an edit app, the view inherits from scroll view, and I draw most things manually. I need an insertion indicator, which may refer to caret(as I know windows use this term) or cursor(not the mouse cursor). I am not sure what term apple use.
I googled before and I know I can draw it as a line manually, or create a clear background text view over it, but I don't like these ways. I hope there are system APIs to do this, which is more native. Any one can figure out?

How to create custom keyboard like real keyboard in iOS?

I have to create custom keyboard like the real keyboard in iOS.
I need to do following like keyboard.
like that.
How can i create like that?
Please tell me , because i'm just new beginner.
Here's something that I created that might help. Just fork it on GitHub and change the Punjabi characters to Myanmar. Most of the hard work is done for you :)
https://github.com/kulpreetchilana/Custom-iOS-Keyboards
With a custom view and custom buttons. The keyboard itself is something very easy to do, you just need to place some buttons on a view and then show that view.
Your real problem will be connecting the button actions to the text field.
You would have to check for the first responder and then add to its text the value corresponding to your custom keyboard. It will be an even more difficult problem to actually "type" those weird characters from the keyboard in the text field. I am not familiar with them, are those real ASCII characters?
Anyway, you're in for quite some work. It's not something very difficult to code, requiring some complicate algorithms, but the implementation will be tricky and complex, so be careful

how do i make UIKeyInput make repeated deleteBackwards calls

Currently I am using UIKeyinput but it is only sending a single delteBackward event even when I hold down the delete key for a long time.
How can I make it send me multiple event calls when I hold delete down for a long time?
There is no easy way to have the system keyboard do auto-repeat. These leaves you with two options:
Fake it by using an overlay on the keyboard (see the comment by #pho0)
Implement a custom keyboard, install it as the inputView for your view or view controller and implement a custom protocol that supports auto-repeat.
Solution 1 works well if you only need the delete key to auto-repeat, but if you need all the keys to auto-repeat the overlay code becomes as complex as the custom keyboard option. (The overlay needs a rectangle for each key, so why not just replace the underlaying keyboard).
Solution 2 involves a certain amount of "up-front" work... One way you might do this is define a key cap class (like a physical key) and a keyboard layout class.
I have implemented both solutions in projects I have worked on, but I currently use solution 2 since I can create whatever keyboard I like. In the simple case the use need never know that it is not the system keyboard. For power users they can customize the keyboard as they see fit.
For what it is worth, I found it useful to have the keyboard class be dumb; it just communicates that a key has transitioned to being down or has transitioned to being up. An additional class above that decides what action should be taken.
In some ways, I know this is not the answer you were looking for, but I hope it helps,
IDZ
One thing I've seen people do is put a fake button on top of the keyboard button. When someone is holding down on it, have a timer remove the last letter every time it fires.
Hope this helps.

Resources