NSTextView scroll point changing when edits applied - ios

I have an NSTextView that users can type into. What's different is that I often make changes to the TextStorage while the user is typing in it (i.e. some information comes in over the network, and I need to represent that into the NSTextView by merging in these changes).
I can do that successfully - I've created a MovableCursor which keeps track of SelectedRange even when changes are happening behind the scenes.
I have this code working on iOS (UITextView) and the Mac (NSTextView). The problem is, on the Mac, the NSTextView usually jumps in the Scroller (i.e. the visible position in the View changes). It does not move at all on the UITextView - everything works perfectly, the cursor doesn't move in the window even though changes have happened to the TextStorage.
Simply using ScrollRangeToVisible doesn't work - it may make the Selection visible, but it necessarily make it visible in the same place.
I've tried grabbing the Scroller's VerticalScroller position, and then reapply it after making changes.
var scroll_pos = contentViewScroller.VerticalScroller.FloatValue;
...make changes...
contentViewScroller.VerticalScroller.FloatValue = scroll_pos;
Well, I can see the scrollbar doesn't move (expected), but the text still does. Somehow the scroller gets out of alignment with its position through the NSTextView. When I start moving the scrollbar, it seems to "flick" a little and get back in alignment.
So... Any thoughts on how I can make changes to an NSTextView's TextStorage, while keeping the Cursor (or SelectedRange) fixed in the same position on the screen.
[Note: of course there are times when this immobility is not possible - for example if everything before the cursor was erased, then the cursor must move to the top. That's ok.]
Many thanks.

Related

UIPanGestureRecognizer resets position after navigating

I have a UIView that can be translated along the X-axis. Everything works great but I noticed that if I navigate to another page and back, the new view position is lost and reset to how it's configured in the xib.
In iOS8, it actually works exactly as I would want; the view persists its last position. However in iOS7, this doesn't appear to be true so I'm guessing Apple fixed it in their latest os? Is there a workaround anyone knows of that can get this to work in iOS 7?
Try storing the last location and when you pop up your controller set the view's x-axis to this stored location

Interrupting UIScrollView Bounce after it has started?

I have a UIWebView that loads a new request when the user scrolls a set distance past the end, or before the beginning of the content (ie. into the area that "bounces" back), via the scrollView delegate
Unfortunately, I have found that once the bounce animation starts, it has to complete, and completely bounce back to the edge of the content area, before the UIWebView will display the new content that it has loaded.
Is there any way to interrupt this, and have it not need to bounce back before displaying the new content? I would prefer for the old content just to disappear without needing to bounce all the way back to its edge . Either that, or speed up the animation.
Things to note:
I do NOT want to turn off bouncing.
I have tried importing quartzcore and using -removeAllAnimations on every view I can think of, including the superview, and it doesn't help.
I have tested it, and it is not because of latency in the loading of the request that is causing the delay in displaying the new content.
There are a few UIViewAnimationOptions that look like they could be helpful, but I can't see where I would use them, and I don't really want to subclass UIWebview if I can help it.
Any ideas?
thanks in advance

UITextView Cursor Moves When Editing Begins

When a user taps into my UITextField the field clears and the cursor moves up outside of the bounds of the TextField. The issue corrects itself once the user has entered a letter, but will recur every time the field clears on edit.
The TextField was created in a storyboard and nothing was done programmatically, auto layout is also turned off on the storyboard. Any ideas?
Also, the cursor moves down instead of up if the user had entered text, leaves and returns to the app.
I should note that this doesn't happen in simulator, only on actual hardware.
Thanks in advance for any ideas anyone has.
EDIT: Unfortunately my low reputation won't allow me to post screenshots.
EDIT 2:
After doing some research on the topic, I've found my problem is two-fold:
The cursor is actually just shrinking when editing begins and the field clears. Playing around with content alignment in IB I was able to figure that out.
If the app is closed out of during editing and reopened the cursor and text move downward, outside of the visible area of the TextField.
Well, I don't know what I was doing wrong, but after playing with things a bit longer, I removed and recreated my label and the issue resolved, so I must have messed something up in IB that was causing that behavior, as I didn't change anything else.

For iOS how do I create a draggable button within a button?

In xCode I'm making an iPad app, and have created a series of counters in UIimageViews that drag around the screen when you touch them. All good so far.
But now I want to have another smaller hidden button just above each counter that is disabled, so that when you tap on the counter the smaller button can appear and can perform an action (such as 'return to starting position' or 'hide'.
I'm just not sure where to go with this one now. Any ideas or hints would be much appreciated!
So you create the buttons and set their frames and add them as sub views to your view. From that point on you can hide them by making their alpha = 0.0, have them appear disabled by setting alpha to say 0.5 (set enabled to NO), and make them live with alpha=1.0. You can animate frame and alpha changes. For convenience you can set their tag properties to a value related to the counter so you can easily get them using viewWithTag:.

Blackberry pixel-specific animated focus scrolling

Suppose I have a VFM full of both focusable and non-focusable fields. Since most of them are spread out far apart, the movement from one focused field to another is jerky at best, even with NullFields in between. In other words, it just sets the current y position to the next focused field without smoothly scrolling the screen.
What I want to achieve is to be able to scroll at a fixed rate between fields, so it it doesn't just focus from one to another that instantaneously. After reading up on how to do this, it is a matter of overriding moveFocus and setting it via a TimerTask from an accessor method to set moveFocus, as per this link. However, I haven't seen a practical implementation of how to do this, complete with the routines that are called in the TimerTask's thread.
Is there any way to achieve this type of behavior?

Resources