I've read a million posts on stackoverflow about nstimers, runloops and the main thread but they don't seem to have the same problem or answer I'm looking for. My situation:
- I'm trying to animate some stuff while there is some 'loading going on'. The animation consists of a couple of scrollviews going back and forth using the contentOffset. I do this animation using an NSTimer.
- The 'loading going on' of point 1 is in fact not some simple loading, but some drawing on some other UIViews not currently visible to the user.
So to conclude, I'm trying to animate some scrollviews while drawing at the same time on UIViews. Is this even possible without them conflicting in such a way the the animation is not smooth? If I use a activityIndicatorView it's definitely possible, the spinning wheel never stutters, it's always spinning smoothly. I've tried to use runloops but I couldn't figure it out. Here's some of my code so far:
-(void)startLoading
{
[self performSelectorInBackground:@selector(showSpinningCells)];
[self drawOnViews];
}
-(void)drawOnViews
{
//HERE A LOT OF VIEWS ARE BEING UPDATED AND CALLED SETNEEDSDISPLAY
}
-(void)spinCells
{
//HERE I USE PERFORMSELECTORONMAINTHREAD TO SET THE
//CONTENTOFFSET OF THE SCROLLVIEWS
}
-(void)showSpinningCells
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
spinLoop = [NSRunLoop currentRunLoop];
spinTimer = nil;
self.userInteractionEnabled = FALSE;
spinTimer = [[NSTimer scheduledTimerWithTimeInterval:0.2
target:self
selector:@selector(spinCells)
userInfo:nil
repeats:YES] retain];
[spinLoop run];
[pool release];
}
Please tell me if this is even possible before I try anything further and if so, how? Currently I never see any spinning. I do see spinning if I don't do anything afterwards, but as soon as I call the drawing on the UIViews the spinning completely stops.