Reverse animation before it is finished - objective-c

I have a button and when the user touches down and holds a popup appears. However, when the user releases his thumb before the pop animation finishes I'd like the animation to stop where it is and autoreverse to the initial position. How can I accomplish this?
Currently I'm simply using UIViews -animateWithDuration:animations:completion:. Do I have to set the animations explicitly in this case?
I've already tried reading the current state from the presentationLayer properties, but that somehow didn't work.

You can start the second animation using the UIViewAnimationOptionBeginFromCurrentState option. This will stop the first animation if it's still running.

Related

Updating UITextView inside UIScrollView while scrolling makes the scrollView stop scrolling

I have a scrollView that contains 12 UIViews set as tiles. Each tile contains a textView.
The scrollView has pagination enabled. So, you have 12 tiles per page and you scroll horizontally.
I am updating the textView whenever I receive information from an API call.
This is updating the textView correctly, but I have a huge problem. Whenever the update happens, the scrollView actually scrolls to the view that was just updated. So whenever I load a new column of tiles, the scrollview stops when it begins loading it, even if it has momentum!
Any idea what might be causing this?
If I lazy load the cells without any information in them everything works right, so I'm thinking it has to do with me updating the textView.
I have already tried:
Using an NSTimer (and setting its mode to NSRunLoopCommonModes).
Using an NSOperationQueue and calling the main thread whenever I need to update UI changes.
None of those worked.
i think the solution lies within your post:
"Using an NSOperationQueue and calling the main thread whenever I need to update UI changes."
Whenever scrollView calls for willScroll, stop the current Images being downloaded & when the scroll view stops scroll & its delegate method is called start the new queue to download images.
My suggestion will be debugging it using instrument. In instrument there is a trace template named "Time profiler", you can actually see how much time your application spends on each tasks.
But if you are updating the textViews, of course the main thread will be blocked, so the scroll view stop scrolling until all the textViews are updated. So my suggestion will be tweaking the performance.
Maybe you are loading too much things in each textView?

Touch detection without event processing

I am using cocos2d. I would like to be able to detect whether the screen is touched at a particular instant - that is, rather than intercepting an event when it occurs, I want to detect the presence of touch at a particular moment.
The reason is that I am animating sprites and want to determine if the sprite should keep moving - if the screen is still touched. I cannot use ccTouchesEnded because each time an animation starts I set isTouchEnabled to false because I also want the user to be able to tap rapidly on the screen to move the sprite but if they tapped too rapidly, it would mess with the position of the sprite during the animation process - which I have found screws up the positions of my objects in weird ways.
Is this possible?
There does not appear to be any public API to detect touches other than enabling and receiving these events in the main UI run loop.
You can keep handling events, and set the state left by the last touch event in a model object or global variables. Then you can poll your app's own internal state at any time.
Instead of disabling touches, you can just have your touch handler not do inappropriate things if the event time stamp is too close to some animation start time.

Showing a keyboard in iOS without animating

Does anyone know if there is a way to show the keyboard in iOS without animating it? Or better yet, can you change the animation speed?
Thanks
The only way I know of, is pushing a view controller which has a view which is made first responder in -viewDidLoad. (viewWillAppear will probably do fine as well)
Pushing it without animation might get you a keyboard popping up without animation.
update too bad, it seems either the view animates into screen (modally or pushed on the navigation stack, with animated:YES) with the keyboard fixed, or the view comes up without animation (i.e. animated:NO) making the keyboard animate into screen again.

Undo button for drawing app

I made an iPad drawing app and I want it to have an "Undo" button that will remove the last object drawn on the screen.
How can do that? I already have the button connected to its outlet and action.
Essentially, you will need to keep a version of the the image before the new object is drawn on it, and if the user decides to abandon the drawing, revert back to the previous image.
If you want more then one level of undo it may be easier to keep a description of all of the actions performed by the user and repeat them up to the last undo.

How can I differ between manual and automatic scrolling in NSScrollView/NSTextView

I subclassed NSTextView and added support for automatic scrolling in a userdefineable time.
Now I want to detect, if the user manually scrolls, while the view is scrolling automatically.
Then I want to immediately stop automatic scrolling, until the user stops his action and then I want to start scrolling again from the new position.
I want to do this in such a matter, that the user can move around without a stuttering view.
I use boundsDidChangeNotification to calculate the scrolling position (playtime) and show it in a label, but I can't use it to detect the user manual scrolling, because it is also pushed by the automatic scrolling...
Would be very nice, if anyone has an idea ;-)
Thanks in advance
Gerald