iCarousel disables any other animation done in the background - objective-c

I am using Nick Lockwood's iCarousel to display images, and I need to make a transition between backgrounds behind the carousel when the carousel stops at an image.
I am using UIView's animateWithDuration, and the problem is that the animation completion happens instantly because iCarousel is calling [CATransaction setDisableActions:YES];
I deleted the call to disableAnimation and enableAnimation in Step method of iCarousel, and now my transition animation works fine, but I'm afraid some functionality will be missing or strange bugs will occur now.
can anybody concur or suggest a different approach for this?

The [CATransaction setDisableActions:YES] is partly for Mac support and partly to prevent weird resizing effects when item views are loaded. If you aren't seeing any problems then it's probably safe to disable those lines, but you're generally better off not modifying the library if you don't have to as it makes it more difficult to upgrade to a new release later.
When are you triggering your animation? If you only want it to happen when the carousel comes to a stop, the correct place to do it is probably in the
- (void)carouselDidEndScrollingAnimation:(iCarousel *)carousel;
Delegate method. If you do it there you shouldn't have problems with the animation being stopped. If you are already doing it there, and you are still seeing problems then a workaround is to delay your animation until the next runloop update, which you can do using GCD, like this:
dispatch_async(dispatch_get_main_queue(), ^{
//perform your animation code
});

Related

What may cause all UIView animations to finish instantly?

I have an iOS app where I use a lot of UIView animations. They'll all work perfectly for a very long time, then suddenly all animations finish instantly instead of using the specified duration. No errors and the app still functions, but the animations don't work properly.
The app will do a lot of downloading small graphic files in the background then call a selector on the main thread to present the graphics.
Does anyone know what may cause this kind of behavior?
I know it's not okay to handle UIKit in backgrounnd threads but thought it was limited to all drawing, like adding subviews etc. It seems creating and changing views (without adding them as subviews) is not okay either. My problem in particular was creating UIImageViews in a background thread. I changed the code to load into UIImages and create the UIImageViews in the presentation code, which is run in the main thread and now it's completely stable.

Can I build UIView elements on a separate thread?

I have an app that has to load and render a fair amount of content onto screen (mostly loading from a database).
I won't post all the code here but in effect it simply builds up a set of UIView objects that are added to a UIScrollView object. Nothing too complicated, just loaded quite a lot of stuff. This currently takes a second or so render everything (running on the main thread).
I want to show an activity indicator whilst the loading is happening, and I think the best way to do this is to have the method that takes a long time happen on a background thread and "report back" when it is complete.
The question is this. I know all the actual drawing is done by the main thread, so is it possible to create a new thread and have that build up a set of UIView objects that are then drawn on screen?
there is a great WWDC2012 session video, that deals exactly with your use case:
WWDC2012 Building Concurrent User Interfaces in iOS
Basically the trick is to prepare and draw the views on another queue and ship it over to the main queue.
You are correct. All the UI work should be done on the main thread. In your case I would suggest you to add the UIView object which are visible to the scrollview and add rest of them only when scrollview starts moving to that point. You can keep on adding views once they are about to be visible and remove any views which are not needed from the scrollview. This normally helps in better memory management.

Disabling buttons before view rotates

So been working on another app recently for iOS which incorporates a UIImagePickerViewController. App is ready to go and all works fine under normal circumstances, but if the user is being eratic and pushing buttons whilst rotating the iPad, then things go slightly awry and views load in the wrong place.
So basically, I want to disable all my buttons before the iPad is rotated and enable them again after the view is done rotating.
I thought this would be easy using the
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
and
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
methods.
But because the UIImagePickerController is being displayed, this for some reason stops these methods from being called. So I can't use these methods.
So basically, what I'm asking is if anybody can think of any other ways that I could achieve this??
Thanks,
Matt
You could subclass UIImagePickerController and then implement those methods on your UIImagePickerController subclass.

Transition between NSImageViews in Objective-C

I am not very familiar with the Mac OS X APIs (coming from a long background of iPhone sdk) and I was wondering how I could add a transition when I switch nsimageviews. Does anyone have a short code snippet they can share about how to go about doing this?
This tutorial does pretty much the same thing, albeit with some extra things you probably don't need: http://www.cimgf.com/2008/03/03/core-animation-tutorial-wizard-dialog-with-transitions/
In short, just call
[[myWindow contentView] setWantsLayer:YES];
[[[myWindow contentView] animator] replaceSubview:currentView with:newView];
to do a crossfade animation of the two views. If you want to do a different type of animation, the fourth block of code in the tutorial should be of help.
Be warned that using Core Animation layers ruins your font rendering, so you'll probably want to setWantsLayer:NO after the animation is complete also.

Is there an optimal way to render images in cocoa? Im using setNeedsDisplay

Currently, any time I manually move a UIImage (via handling the touchesMoved event) the last thing I call in that event is [self setNeedsDisplay], which effectively redraws the entire view.
My images are also being animated, so every time a frame of animation changes, i have to call setNeedsDisplay.
I find this to be horrific since I don't expect iphone/cocoa to be able to perform such frequent screen redraws very quickly.
Is there an optimal, more efficient way that I could be doing this?
Perhaps somehow telling cocoa to update only a particular region of the screen (the rect region of the image)?
setNeedsDisplayInRect: does exactly what you need.
See documentation at developer.apple.com