I am working on some CoreAnimation materials. Navigation controller with multiple controllers. Presentation controllers have UISCrollViews for different brochure "pages". On each page, an animation may appear that fires when the user flips to this page.
I tried something like this (for one-time animations).
void (^animationBlock)() =
^{
static bool alreadyTriggered = NO;
if(alreadyTriggered)
return;
[CATransaction begin];
[CATransaction setCompletionBlock:
^{
alreadyTriggered = YES;
}];
[CATransaction commit];
};
NSMutableDictionary* pageBlocks = [[NSMutableDictionary alloc] init];
[pageBlocks setObject:[animationBlock copy] forKey:<animation name>];
[self.animationBlocks setObject:pageBlocks forKey:<some page number>];
[pageBlocks release];
[animationBlock release];
"animation name" and "page number" are placeholders for explanation (these are arbitrary NSString literals).
And the code that runs these animations is as follows:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int pageNumber = floor(self.scrollView.contentOffset.x / self.scrollView.frame.size.width);
NSMutableDictionary* pageBLocks = [self.animationBlocks objectForKey:[NSString stringWithFormat:@"page%i",pageNumber]];
[CATransaction begin];
for(id key in pageBLocks)
((void (^)())[pageBLocks objectForKey:key])();
[CATransaction commit];
}
So far, so good, only if I pulled out the brochure from the navigation controller (like the dealloc calls in the brochure) and then reinsert it, the static bool is still installed.
My thoughts:
- ?
.. ( ) , dealloc .
- bool?
bool , . Objective-C, . , popViewcOntroller. , ?
? Apple, , , . , ...?