Fire action when UIImageView animation is done - objective-c

In the world of delegates and detectors, I'm having trouble finding a method for detecting if an animation I am playing is playing or not. Once the animation is done, I want the UIImageView to fade out and remove itself from its superview.
I am using the common animationImages value of the UIImageView.
Right now, I have a once-per-second looped checker looking at the UIImageView's animates value, and determining if it's still playing.
But this feels a bit excessive, so does anyone know a smarter method of doing this, possibly with custom classing the UIImageView if thats what it takes ?

If you are using UIImageView's animationImages property, then you might need to follow Eugene's solution.
Immediately after calling the UIImageView's startAnimating method, you start an NSTimer which has to be fired after animationDuration. In the fired timer method, you could hide the imageview.

If you are setting you're UIImageView's animationDuration property, why don't you try creating a timer which will fire after that same duration and set your UIImageView hidden in some method?

Related

How to stop uiscrollview scrolling where user stopped touching the screen

I have a UIScrollView, and what I need, is that when the user stops dragging it, the scrollview stops scrolling to.
Sometimes it works, but sometimes, the scroll continues when the pression is released.
I tried a lot of things with the scrollView.tracking, or with delegate methods like scrollViewDidScroll, or scrollViewDidEndDecelerating, etc. But for the moment, I didn't found anything !
I also tried UIPageControl but I need my scroll view to stop every 50 pixel.
Thank you for your time and your help !
You need to impelement this method (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate the decelerate parameter means should scroll view stop immediately or not. Try to use decelerationRate property to set the needed rate.

UIWebView redraw on rotate

I have implemented a UIWebView object into a custom UIView (TSAlertView). My UIWebView sits in the middle of the UIView, as a subview.
When I rotate the iOS device screen, the UIWebView object redraws right on top of the old one, without deleting the old one. All the other elements of this custom UIView are destroyed and redrawn when the screen is rotated.
I imagine I must have missed some sort of procedure for deallocating resources or removing the UIWebView from view. I have tried adding 'autorelease' to the declaration of the UIWebView, but to no avail. I wonder if this is a common symptom of a simple oversight I have made in the way the UIWebView is created?
This seems to be a simple case of not telling the UIWebView object it should destroy itself before it is redrawn on each rotate - but I don't know how I can go about this...
Any wisdom gratefully received.
Ideally while rotating you should not create the views again. Instead you can rearrange the frame in delegates appropriately. In your case you might be creating a UIWebView again, which should be avoided. Instead of that, you can keep it as a class level param(Declare in .h file) and adjust the frame in delegate methods for rotation. Also please note that release/autorelease wont remove your view from superview. You need to call removeFromSuperview method to achieve that.
Check this for view resizing and layout handling

Draw NSImage while space switching?

Currently in my project i've a simple nsimage which is updated via drawRect function.
I need to change the nsimage when the user switches between spaces... so i set my new image and called setNeedsDisplay when the NSWorkspaceActiveSpaceDidChangeNotification triggers.
The problem is that the drawRect method seems to be called to late... in other words, the previous image appears briefly before the new one. Is there any way to run the drawRect method while the transition between spaces is running? or any other way to accomplish the desired effect?
Thanks

Looking for guidance on detecting overlap of UIImageViews

The scenario is that I have a UIViewController containing multiple "InteractiveUIImageViews" (inherited from UIImageView) each containing their own UIImage. In InteractiveUIImageView I have iplemented methods for touchesBegan, touchesMoved and touchesEnded to handle their movement and behaviour on screen. Certain objects of this type will be set as 'containers' (think recycle bin) with the objective being that when one image is dragged onto it, it will be removed from the screen and placed inside it to be potentially retrieved later.
My current thinking would be to call a new method in UIViewController from the touchesEnded method of my InteractiveUIImageView but being new to all this I'm not really sure how to go about doing that (e.g. calling a method from the 'parent') or indeed if this is the best way to achieve what I want to do.
Thanks in advance for any advice.
I'm afraid your question is (too me at least) a bit unclear. I get that your are trying drag a UIImage around a scene and drop it in drop-locations.
What is unclear is you class hierarchy. I believe that you are going about it in a wrong way. You shouldn't have to subclass UIImage at all.
Instead I would urge you to let the UIViewController manage the movement of the images. When you touch down on an image, you also touch down on its parent (containing) view.
What you have to to is then reposition the UIImage (all handled by the UIViewController) as you drag the image across the screen. When you let go you check if your finger was inside your drop-zone on touch up.

UIView. How do I redisplay a "data driven" UIView?

I am doing a scientific visualization app for iPhone. Periodically a UIView subclass will receive some data from the network that it must render via its overridden drawRect: method.
My challenge is that there is no way to indicate to Cocoa-Touch that this data has arrived - or changed - other then [myView setNeedsDisplay] which is ignored except for changes to the bounds of the UIView. I have tried hiding and unhiding. Nuthin'.
Maddeningly, since all I did was alter some internal state of the UIView [myView setNeedsDisplay]. This change is completely invisible to Cocoa-Touch. This change is not one of the criteria that warrents a redraw - according to Cocoa-Touch - thus my UIView sits there, unchanged.
This is very, very, very frustrating. I have hit a wall here.
Could someone please suggest a technique, a trick, a hack, that will prompt my UIView to re-render.
Cheers,
Doug
[myView setNeedsDisplay] should cause drawRect: to be sent to myView the next time you're back in the run loop and myView is visible. If changing the bounds is causing the view to redraw (myView.contentMode is UIViewContentModeRedraw), then setNeedsDisplay must be working, since that's how the redraw is signalled by the bounds change. See the UIView class reference for details.
Is your drawRect: being invoked the first time the view is shown? If not, it may be misspelled, overridden in a subclass, or even on the wrong object.
Is the view visible and on screen? It won't be drawn if it is off screen.
Is control returning to the event loop? drawRect: won't be invoked if your application is busy.