Have UITextView make first line current cursor position? - iphone

Long story short I need to get a UITextView to automatically scroll to the current cursor line, however I need one additional thing. Instead of just having the TextView be scrolled "in view", I need the cursor line to be in view specifically as the first line of the textView.
Any ideas how to accomplish this?
Thanks.

[UITextView -selectedRange] will return the insertion point as the location member
[UITextView -scrollRangeToVisible:] will scroll to the specified range
Combining the two will enable you to scroll to the current cursor line.
Based on your comment, it sounds like you most likely want to adjust the frame of the text view when the keyboard is shown.
Apple provides some nice notifications:
UIWindow Class Reference - Notifications
UIWindow Class Reference - User Info keys
Make sure to check the supported operating system version as iOS 5.0 brought some new, and better, notifications and user info dictionaries

Related

how to detect a password text field when running in the background?

I am developing a screen recorder and facing a crazy requirement. My boss would like to have an option for a user to automatically pause recording when the current view has a password field. (That view might belong to a third-party app.)
So, is it possible to check if the topmost view has any password text field?
This is an enterprise app so private api is allowed.
Any pointer from jailbreak community is also welcome.
It would be much easier if you could just use your own views but this should work for either your own views or a third party view. BUt anyway, every time you would load up a UIView check all of its subviews, in the ViewDidLoad Method i would think and for each subview check for its class type in your case it would be UITextField. Since these are the only textfields where you can set secure text entry as its text type. Every time you find a UITExtView check if its secureTextEntry is equal to TRUE. If it is true disable the recording until that view is removed from the screen. That should be what you need.

iOS -- dealing with the inability to set the cursor position in a UITextField

I am working on an app that will use a custom keyboard for text entry. The keyboard should have "forward" and "back" keys.
Some hunting on SO suggests it is impossible to programmatically set the cursor position in a UITextField.
I've looked at using a UITextView instead. This does allow one to set the cursor position. But the scrolling behavior gets extremely annoying.
I am wondering if anyone is aware of a good workaround. Basically, I want something that has text and a cursor, and I can programmatically set the cursor position.
EDIT: Intriguingly, if I have a UITextField in the simulator and I press the forward or back arrow key on my mac keyboard, the cursor does move forwards or backwards. However, I can't see any way to mimic this behavior on a device . . . or, for that matter, with a mouse click on the simulator screen.
The accepted answer was correct at the time but is now out of date. In iOS 5, UITextField conforms to the UITextInput protocol. The cursor position can therefore be set via the selectedTextRange property.
I also use a UITextView for the very purpose of being able to set the cursor position.
If you subclass UITextView (which itself is a specialization of UIScrollView), you can override "scrollingEnabled" and return NO:
- (BOOL) scrollingEnabled
{
return NO;
}
I also had to play with the contentInset and contentOffset properties to get exactly what I wanted.

Focus and zoom in on a UITextField when touched?

How in the world does one get the iPhone view to zoom in on a focused UITextField? I need to tap on a text field that I want to edit, and my view should zoom in to the tapped text field and pull up the keyboard (which it already does), similar to how many Internet text fields gain focus on the iPhone. Is this some type of overlay?
I've been looking everywhere for this solution but maybe I've just got the wrong terminology. Thank you in advance.
Could be a duplicate of this StackOverflow question.
In essence, there are a number of ways, but you have to program this effect manually. A textfield is already an overlay. You can either move it, or scroll the containing view.
Please follow the following steps.
Implement the delegate method for all textfield.connect the outlet of textfield in interface builder basically it's setting the delegate property.then in delegate property you can defined the method whatever you want to implement or wanted to do functionality.
Thanks

Custom Number Pad UIKeyboard

How would I go about creating a custom number pad like what is used in 'Tipulator' and other apps.
I know how you can customize UIKeyboard, but their number pad doesn't look at all like the default number pad. Is it even a UIKeyboard or a separate UIView?
I've been working with keyboards for quite a time. I would say that the easiness of this depends on what your target text input view is. If is a UITextView then we are fine, if is UITextField you might have some problems because you don't have access to current cursor text position like un UITextView.
(You might check UITextView and UITextViewDelegate methods)
If you just want to set a string and don't mind current cursor text position, then you don't need a keyboard. (I think this is the case of Tipulator)
BTW: I just saw Tipulator in youtube and there is no necessity of a keyboard for doing that.
Judging by the looks: It's a custom UIView subclass. Basically, it's just a panel with 11 buttons on it, so it should be rather easy to do.

iPhone SDK: How to create a UITextView that inserts text where you tap?

I'd like to create a UITextView that you can tap anywhere within it and start typing at that location. The default behavior of the control is that typing starts where the last character ended. So, if I had a UITextView with no text in it and tap in the middle of the control, I'd like typing to start there--not in the upper left.
What is the best way to implement this behavior? I've considered making the default text value of the view to be 3000 space characters or something similar, but this seems like not an elegant solution. Suggestions?
I suggest deriving from UITextView to create a custom view that handles taps. You'll want to override the following methods, probably:
touchesBegan:withEvent
touchesMoved:withEvent
touchesEnded:withEvent
touchesCancelled:withEvent
Make sure the userInteractionEnabled property has a default value of YES. Override hitTest:withEvent and pointInside:withEvent to figure out where in your view the user tapped.
Be sure and read the Responding to Events section in the View Programming Guide for iOS, and also see the Event Handling Guide for iOS for more details.
Anyway, once you figure out where the user touched, you can modify the text or reposition the karat as appropriate.